0 votes

If I use Navigation2D, my agents seek only for shortest way. But this way is not always good from tactical point of view. For i.e. short way can go through area occupied by soldiers with whom we don't want to fight (or area can be locked by enemy sniper. Or there can be a mine field. Or shortest way to cover move agent to it without keeping covering obstacle between agent and player).

How to increase Navigation2D by ability to use that additional tactical information to find the optimal way? Can I do it by script or should I recompile the Godot?

asked Jul 16 in Engine by Robotex (129 points)

1 Answer

+1 vote
Best answer

Hi,
no, Navigation2D cant do that for you. Imho i think the aStaral gorythm is suited way better for that task. But the implementation in godot is so simple that it cant provide a good solution for this either.
But the aStar algorythm is so simple and well documented that you can write your own in no time. Then you can implement your own field evaluation method into the calculation.

answered Jul 17 by klaas (2,176 points)
selected Jul 20 by Robotex

you can write your own in no time

Yes, I think so. Actually, I already have written at my own engine using c++, but I don't know how to integrate it to Godot. Where can I see the Navigation2D or Astar2D sources to use it as example when create my own godot component? Can you point me to the right place at sources?

this seems a good astar explanation
https://www.geeksforgeeks.org/a-search-algorithm/

you can search the original source here
https://github.com/godotengine/godot

and i remeber i once found a cpp addon for godot. But i havent remember/found it yet.
Google it yourself

i would advise your is
- dont make it grid based, make it node based. Its way more flexible that way.
- dont make it a "run once solution", make it interuptable. Astar can be quit resource hungry. If you dont want your game to hang while calculating a long path you have to interupt the search process and continue it the next loop. (Godot doesnt do that and its nearly unuseable because of this)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.