How to create a pathfinding system in a platformer?
I’ve created a background grid, and I want to make it so that from the cell where the player is standing, numbers are propagated to neighboring cells, increasing by one with each step.
I managed to assign coordinates (X;Y) to each cell, and I can also assign the number 0 to the cell where the player stands. But I don’t know how to explain to the neighboring cells that they should assign themselves +1, and so on down the chain.
The idea is that the enemy will move toward the player by following cells with lower numbers — essentially taking the shortest path.
Overall, if there are any existing solutions for NPC pathfinding, or ideas for how to make this system simpler, I’m open to suggestions. The built-in pathfinding behavior is useless in a platformer, and I haven’t found any real alternatives.
Thanks, Yes, I came across that post and video, and it looks amazing, but unfortunately, I didn’t fully understand what he did. There’s no tutorial or even a screenshot of the events, so I couldn’t implement his approach. He mentions invisible obstacles for the pathfinding plugin, but in the video you can clearly see nodes, and I didn’t quite get how everything is set up there. Maybe you could give me a hint?
I tried to come up with something on my own, but also hit a dead end. In the end, I decided to write on the forum and try my luck. =)
The nodes you see are part of the path drawing extension. Ignore them, they’d be more useful for debugging.
The invisible obstacles would just be hidden sprites with PathFinding Obstacle behaviour attached. For example, the pink semi-transparent sprites in the image below could be the hidden pathfinding obstacle objects:
This will force the enemy, the red squares, to move along the bottom of the screen and then up the ladder instead of just moving diagonally to the middle of the ladder.
It also forces the enemy to “jump” the obstacle in the top left platform, instead of floating towards the player.