Understanding Goal-Based Vector Field Pathfinding
Why Game Development Stack Exchange recommends it
Game Development Stack Exchange answerers link it as a quick visual reference when suggesting flow fields or shared paths for many units chasing the same target.
Recommended by 0 people across 0 different months, 2016 to 2019.
What it is
A short Tuts+ Game Development tutorial in which Sidney Durant explains goal-based vector field pathfinding. It covers how the technique works and why it can beat traditional pathfinding such as Dijkstra's algorithm when many units share a goal.
What people said
Cites yyny · 2016-04 · Game Development Stack Exchange · on “Locust Swarm algorithm for path finding (devour and move on)”
Is this [this video] what you want? As for finding the closest food stack, calculating the center of the swarm and using a simple A* algorithm to search all other food stack from the lowest minimum distance to the highest works, or even just a lookup table to map food stacks with their nearest neighbours (Only works if your food stacks are static and regrow). EDIT To further answer the question: The above solution might or might not work based on the new requirements stated in the comments. Or rather, it works, but becomes quite a heavy computation quite quickly. You can assign N swarm members to stay at the food stack, and let the rest search for another stack. However, I would predict that the
Cites BlueRaja - Danny Pflughoeft · 2017-10 · Game Development Stack Exchange · on “Is A* efficient even when the obstacles are moving?”
There are multiple algorithms that are much faster than A* when you need to recalculate a path with moving obstacles. See here [LINK] under "Simple Recalculations". However, you're not likely going to find an off-the-shelf solution for any of them, so in 99% of cases they're overkill for a game. Your time would be better-spent using an existing, fully-optimized A* solution, and using the common existing tricks for speeding up pathfinding in games: Only recalculating the best path in infrequent intervals Sharing best-paths among multiple units ( example [this video] ) Creating a hierarchical graph [LINK] so you only need to recalculate part of the path etc. You can find more info about these trick
Cites DMGregory · 2019-08 · Game Development Stack Exchange · on “Efficiently pathfinding many flocking enemies around obstacles”
This sounds like a use case for Flow Fields. In this technique, you do a single pathfinding query outward from your player object(s), marking each cell you encounter with the cell you reached it from. If all your tiles/edges have equal traversal cost, then you can use a simple breadth-first search for this. Otherwise, Dijkstra's algorithm (like A* with no goal/heuristic) works. This creates a flow field: a lookup table that associates each cell with the next step toward the closest player object from that position. Now your enemies can each look up their current position in the flow field to find the next step in their shortest obstacle-avoiding path to the closest player object, without eac