Pathfinding to a moving target in evolving terrain

holm.dog

71 points by friendshaver 3 days ago


porphyra - 3 days ago

Pathfinding is a profoundly interesting problem. I think it is very impressive that Starcraft II still has amazing lag-free pathfinding that beats or matches basically every game out there, including very recent RTS games like Stormgate and Zerospace that have a specific emphasis on smooth mechanics for competitive play. Like you can build all kinds of buildings and a zillion zerglings will instantly go around them.

arcastroe - a day ago

The way I remember it: A* can find shortest path between any two given points; Djikstras can precompute the shortest path between a single point and all other points; And Floyd-Warshall can precompute the shortest path between all possible pairs of points.

The author starts with Djikstras and updates the precomputed path-map every frame that either the players location changes or an obstacle is added.

Maybe some more performance can be squeezed out. If the player's location changes more frequently than obstacles are added, it may be worthwhile to precompute the all-pairs-shortest-path (floyd-warshall) which would instead only need to be updated on obstacle additions. The precomputed path map would no longer need to be updated on player location changes.

A similar trick can probably be used to efficiently update the precomputed APSP path-map in these cases, since only a single obstacle is added at a time.

Though if obstacles are added fairly frequently relative to player location changes, this is probably not worthwhile.

a13n - 2 days ago

Couldn’t you just do a breadth first flood fill from the player every time the environment changes? Would be O(n) where n is total number of cells, which would be fast on any hardware or in the browser.

You’d still want to use the directional chart idea.

deadbabe - 2 days ago

Can’t you just use web workers to offload A* path finding to a separate thread and expose results to the main thread through shared array buffers?