How to create a pathfinding system in a platformer?

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.

It may be useful if you try the method explained in this thread.

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.

Thank you very much. I tried, but I still don’t understand the logic. In the example with the little squares, it’s clear they’re using platformer physics and logic — jumping, climbing ladders, gravity. But in my case, the object still “floats” and bounces, even with invisible walls, and sometimes it just refuses to move, even when the path is completely clear.

I honestly don’t want to bother you with all this info, I’m just totally stuck and can’t find a way to make it work. There’s zero information about this online.

No, they’re not. They use pathfinder behaviour. Because the paths are restricted, it give the impression of them having platformer behaviour.

There could be a number of reasons why the chaser get ‘stuck’ and don’t move. One is the cell size on the pathfinding behaviour may need to be decreased. Try changing that first.


The aim of these forums is to help. The more info you give, the better the chance that someone understands the issue and can give help.


Yeah, there aren’t many, if any, pathfinding explanations around.

Okay, thanks for being responsive. I’m starting to understand how everything works there. I managed to implement pathfinding using platformer mechanics—moving right/left/jumping, etc. You CAN do this using the logic of a platformer character. What I did is almost like in the video - the trick is in getting the coordinates of the next node from the object with pathfinding behavior:

(your object with pathfinding behaviour).pathfinding::GetNodeX(1)

where “1” is the next node, because zero is the first one. Same for Y.
So you get the coordinates of the next node and simulate movement toward it using regular platformer behavior—with physics, animations, and all that.

image

In the next few days, when I find some free time, I’ll polish the whole system with ladders and jumping over obstacles. I’ll make a full guide—I promise I won’t disappear. =)

1 Like

Hi all!

Effectively, it’s a good idea and trick.

So, sometimes problems are hard but sometimes their solutions can be easiest.

Xierra

1 Like