+ 15
A* pathfinding question
I recently managed to implement an A * algorithm into my web game, which is used to find the path. This means that I can now select a unit with the mouse and send it to a place on the map. I am extremely excited about this success, but I would need to extend the algorithm to work for multiple marked units at once. If I looked for a path for each unit separately, it would be extremely CPU intensive. But you also have to take into account that the units may be far apart. How would you solve this problem?
3 Respostas
+ 8
You could try to implement an "all sources, one destination" type of algorithm like BFS or DFS for groups of units. For example, I followed this article when implementing pathfinding for my TD:
https://www.redblobgames.com/pathfinding/tower-defense/
You could also look at some suggestions in these threads:
https://gamedev.stackexchange.com/questions/160400/rts-pathfinding
https://gamedev.stackexchange.com/questions/5013/how-does-pathfinding-in-rts-games-work
However, I think most RTS-like games still make use of A*, usually in combination with some other techniques and rules. The following article explores how different games achieved this and implements a group solution from scratch:
https://sandruski.github.io/RTS-Group-Movement/
+ 3
https://code.sololearn.com/cZ0EGJpv6r03/?ref=app