Skip to content
Techniques & Technology

Unit Pathfinding

Navigation intelligence

Unit pathfinding algorithms determine how game units navigate terrain, with RTS games demanding solutions that scale to hundreds of units finding optimal routes simultaneously.

ibm-pccommodore-amigasega-mega-drive programmingairts 1992–present

Overview

Getting from A to B, intelligently. Pathfinding seems simple until hundreds of units need simultaneous routes through dynamic terrain while avoiding each other. RTS games pushed pathfinding algorithms to their limits — A* became the industry standard, flow fields handled mass movement, and hierarchical approaches managed computational cost. Bad pathfinding ruins otherwise excellent games (Total Annihilation and the original Warcraft III had famous pathfinding gripes).

Modern engines (Unreal, Unity NavMesh, Godot) ship with mature pathfinding stacks that abstract these problems away — but the core algorithms haven't changed since the 1990s.

Fast facts

  • Core algorithm: A* (A-star) — Hart, Nilsson, Raphael, 1968.
  • Game adoption: Standard from mid-90s onward.
  • Modern approaches: Flow fields (Supreme Commander 2, Planetary Annihilation), hierarchical (Warhammer 40K Dawn of War 2).
  • Failure modes: Units stuck, choosing wrong routes, "dancing" in traffic, formation breaking.

A* algorithm

A* is the workhorse — a graph search that finds the shortest path from start to goal, exploring nodes in best-first order using a heuristic estimate of remaining distance.

ComponentFunction
Open listNodes discovered but not yet evaluated; sorted by f-score
Closed listNodes already evaluated
g(n)Cost from start to node n (actual)
h(n)Heuristic estimate of cost from n to goal
f(n) = g(n) + h(n)Total estimated cost through n
HeuristicManhattan distance for grid worlds; Euclidean for free-space; must be admissible (never overestimate)

A* is optimal if the heuristic never overestimates remaining distance — guaranteed to find the shortest path if one exists.

For a 100×100 grid with one obstacle, A* typically explores ~1000-5000 nodes vs Dijkstra's ~10,000. The heuristic is what saves time.

RTS challenges

A* alone doesn't scale to RTS:

ProblemDifficulty
Unit countHundreds simultaneously, each with its own path
Dynamic obstaclesOther units move; paths invalidate constantly
Terrain variationDifferent costs (grass cheap, swamp expensive, water blocked)
Formation keepingA group must move as a group, not as individual chaotic agents
Local avoidanceUnits must avoid each other without losing global path
Long pathsA 256×256 map with a long path through corridors stresses A*

The naive solution — A* per unit per re-plan — falls over at ~50 units.

Modern approaches

Flow fields (mass movement)

Instead of computing a path per unit, compute a flow field for the whole map: for every cell, store the direction that points toward the goal. Every unit reads its current cell, follows the arrow.

AdvantageApplication
Shared calculationOne field serves all units going to the same goal
Scalability1,000 units cost almost the same as 10
Smooth pathsContinuous direction field, no jagged grid steps
Pre-computationFlow field can be cached for static destinations

Supreme Commander 2 (2010) and Planetary Annihilation (2014) popularised flow fields for RTS. Total War: Warhammer III uses them for massive battles.

Hierarchical pathfinding (HPA*)

Decompose the map into clusters (regions). Find a path between clusters first, then refine within each cluster:

LevelFunction
Strategic / regionFind route through high-level regions
Tactical / localA* within each region as the unit traverses
ReactivePer-frame avoidance of dynamic obstacles

HPA* (Hierarchical Pathfinding A*, Botea/Müller/Schaeffer 2004) is the canonical formulation. Modern engines apply HPA* to NavMesh structures.

For 3D worlds, the map is decomposed into convex polygonal cells (the navmesh). Pathfinding is per-cell rather than per-grid-square:

  • Far fewer cells than grid squares
  • Naturally handles non-grid-aligned worlds
  • Standard in modern 3D engines (Unity NavMesh, Unreal NavMesh, Godot Navigation)
  • Generated from level geometry by recast tools

Steering behaviours

Local-avoidance algorithms (Reynolds 1999): seek, flee, arrive, wander, flock, avoid. Layered on top of pathfinding to handle dynamic obstacles. The pathfinding gives the high-level route; steering handles the moment-to-moment movement.

Common failures

IssuePlayer experienceCause
Stuck unitsFrustrationPath invalidates and re-plan fails
Suboptimal routesInefficiencyHeuristic too aggressive; cluster-level planning misses local shortcut
Traffic jamsBottlenecksUnit avoidance conflicts at chokepoints
Formation breakingTactical lossMass movement loses cohesion in cluttered areas
"Dancing" unitsVisual glitchTwo units swap path repeatedly each frame; stalemate
Wrong-side detoursVisible inefficiencyPathfinding takes "scenic route" through unblocked but undesired terrain

Notable implementations

GameYearAchievement
Dune II1992Early RTS pathfinding — basic A* per unit
Warcraft II1995Refined A* with terrain costs
Age of Empires II1999Smooth group movement; visible improvement over AoE I
StarCraft1998Per-unit A* with local steering
Total Annihilation1997Notorious pathfinding limits with thousands of units
StarCraft II2010Responsive micro at high unit counts
Supreme Commander2007Thousands of units; introduced flow-field-style approaches
Planetary Annihilation2014Flow fields scaled to massive battles
Total War: Warhammer III2022Modern flow-field hybrid

See also