Game AI & real-time strategy
Pathfinding (A*)
Also: A* search, path planning, route finding
Pathfinding is how a game works out a walkable and reasonably short route for a character between two points. A* is the best-known algorithm for the job: a graph search that combines the distance travelled so far with an estimate of the distance still to go.
Background
Any pathfinder first needs the world expressed as a graph. Common choices are grids (each tile is a node), waypoint networks, polygon navigation meshes and visibility graphs, where the corners of obstacles become the nodes. The choice of representation often matters more for quality and speed than the search algorithm itself.
A* was described in 1968 by Peter Hart, Nils Nilsson and Bertram Raphael. It extends Dijkstra’s algorithm with a heuristic, typically the straight-line distance to the goal. As long as that estimate never overshoots the real remaining distance, A* still finds the shortest path while expanding far fewer nodes. With the heuristic set to zero, A* is simply Dijkstra.
Classic pitfalls: grid paths that zigzag and need smoothing afterwards, characters snagging on corners because their width was never accounted for, and clicks outside the walkable area with no sensible fallback point. Real-time strategy adds another layer: hundreds of units searching at once, blocking each other, while the frame rate has to hold.
How we do it
In the Wurzelwerk engine, pathfinding runs on each scene’s walkable area. nav.ts builds a visibility graph over the corners of the walk polygon and its holes and searches it with Dijkstra. If the target is in direct line of sight, the character just walks straight there. Clicks outside the area snap to the nearest point on its edge, and corner-to-corner visibility is cached.
We deliberately skip A* here: an adventure room has only a few dozen corners, so a heuristic barely makes a measurable difference. Character width is already baked into the area, because the walkable areas for Tatort RMH come out of the Blender pipeline as floor minus obstacles, padded for the width of a character. What pathfinding feels like with many units at once is something our founder knows from his work as an AI developer on real-time strategy in 2000.
Related terms
- Walkable areaAdventure designA walkable area is the invisible polygon in an adventure scene that defines where the player character may walk, with holes for obstacles.
- Influence mapGame AI & real-time strategyAn influence map is a grid laid over the game map in which each cell records how much influence, threat or control a side has there.
- Depth sortingEngine & techDepth sorting decides which character is drawn in front of which, usually by the screen height of its foot point.
- Finite state machine (FSM)Game AI & real-time strategyA finite state machine models behaviour as a fixed set of states with transitions between them, exactly one of which is active at any time.