Skip to content
CoreSource checked

Flow Field Pathfinding

Guides many agents toward a goal by precomputing a direction field over a grid.

Quick Facts

Compact metadata for implementation and discovery.

Category
Pathfinding
Difficulty
Intermediate
Family
Grid Pathfinding
Tier
Core
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
3
Code example
Ready
Visualization
Ready

Overview

Flow Field Pathfinding computes cost-to-go values from a goal and stores the best local direction for each grid cell.

Core Concepts

cost-to-go fieldgrid neighborslocal directionmany-agent reuse

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(G)

Average

O(G log G)

Worst

O(G log G)

Space

O(G)

When to Use

  • Use when many agents need paths to the same target on a grid.
  • Use when crowd movement in games is a central requirement.

When Not to Use

  • Avoid when each agent has a unique target or movement rule that prevents field reuse.
  • Avoid when edge costs or movement rules do not match the algorithm's assumptions.

What It Does

  • Computes integration costs from the goal
  • Stores one best direction per cell
  • Lets many agents follow local arrows

Use Cases

  • Crowd movement in games
  • Many units sharing a destination
  • Grid-based navigation

Inputs

  • Grid cost map
  • Goal cell

Outputs

  • Direction vector per reachable cell
  • Cost-to-go field

Key Formulas (1)

Direction choice

direction[cell] = argminneighbor(cost[neighbor])
direction[cell] = argmin_neighbor(cost[neighbor])

Chooses the neighbor that most reduces remaining path cost.

Pseudocode

  1. 1.Start from the goal cell
  2. 2.Compute shortest cost to every reachable cell
  3. 3.For each cell, choose the neighbor with lowest cost
  4. 4.Store that direction as the local flow
  5. 5.Move agents by following directions

Canonical Example

Input
goal = (4, 4), cell = (2, 4)
Output
direction = east
Explanation
The cell points to its lowest-cost neighbor on the way to the goal.

Implementation Notes

  • Store both scalar cost and direction so the field can be debugged visually.
  • Store predecessor links so paths can be reconstructed after distances are computed.
  • Keep a tiny example with expected output beside the implementation.

Common Pitfalls

  • Ignoring dynamic obstacles can make agents follow stale directions.
  • Mixing heuristic, movement cost, and tie-breaking rules can produce surprising routes.
  • Not defining boundary, empty, or degenerate inputs before implementation.

Interactive Mechanism Walkthrough

2D Grid Wavefront & Trajectory

Show a grid of arrows pointing downhill through the cost field toward the goal.

S
#
#
#
#
#
#
#
G
Step 1 of 5: Start from the goal cell
pathfinding

Notes

It works best when many agents reuse the same destination or cost field.

Sources (1)

What each reference supports for this entry.

Game AI Pro

Book

Game AI reference covering Flow Field Pathfinding implementation model, many-agent navigation use case, and grid-field propagation behavior.

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Alternative toA* Search

Flow fields support many agents moving toward common goals.

Flow fields often compute distances from a destination using Dijkstra-style expansion.

Tags

PathfindingGrid SearchGraphSimulation