I am new to Godot and trying to implement dynamic pathfinding on a 2D map which includes both static obstacles and moving units. As I understand it, Godot's NavMesh makes it almost trivial to generate a path through a pre-baked polygon map [1], as with the solid-line path in the below image. However, I want my game to be able to re-plan the path if an enemy (or other obstacle) moves to obstruct it--as with the dotted-line path in the image. Is this possible with built-in Godot functionality? And if so, how?

Alternatively, how would you recommend implementing a custom pathfinding script in Godot? I am comfortable with vanilla A* and I plan to learn GDScript and/or C#, but in my experience (in Python/Pygame), grid-based A* is much too slow to re-check the path every frame.

Pathfinding Diagram

  • \$\begingroup\$ I don't think real games repath every frame anyway. I've been in game dev many years, but I haven't actually worked on more than about 2 games that use pathfinding. I recall queueing objects for repaths, and the system does a certain amount of it per frame, not even necessarily finishing a whole path check in one frame. This is something you have to implement and then mess with a lot to find the right balance. \$\endgroup\$ – Almo Jun 20 '18 at 18:37
  • 1
    \$\begingroup\$ I think that your experience with A* on Godot will be way better than with Python/Pygame since it actually already have a good low-level implementation of A*. Also, you don't need to check for the path every frame, but only when the character actually reachs the next point \$\endgroup\$ – 648trindade Aug 9 '18 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.