How to implement this simple but complex path system?

Godot Version

GODOT4.5 DEV4

Question

It is recommended that the official add a similar function! The sprite needs to go through 2 to move from 1 to 3, and the sprite can pause the movement at any time during the movement (other events can be executed during the pause) After clicking the 2 or 1 button, the sprite will go back along the path to 2 or 1, I can’t achieve the above effect with Path2D and PathFollow2D, if there is a better way to implement it, please give me inspiration.

You don’t really need pathing for that unless you want the sprite to follow the road. If you want them to follow all the little wiggles in the road, you’ll want to use path2d and a follower.

If all you want is for the sprite to move in a straight line from (1) to (2) and then a straight line from (2) to (3) you can do that just by interpolating the position between (1) and (2), then when you’re at (2), interpolating position between (2) and (3).

You could also do it by giving the sprite a velocity, and putting collision on the numbered points.

There’s lots of ways you could do this. How do you want it to behave?

1 Like

If what you want is “I’m at (1), I click on (3), I want it to go (1)->(2)->(3)”, that’s a pathfinding problem. You can have paths that go (1)->(2) and (2)->(3), but you also want a pathfinding system like A*. You add the paths to a graph, and A* runs a graph solver to say “if I’m at (1) and want to get to (3), what does it look like?”. You get back a list of paths you need to take, in order.