What it does
game.navMesh.bake takes your level's triangles, or a terrain's height function, and bakes a Recast and Detour
navigation mesh from them. The bake is told how tall, wide and agile the agent is, in world units, and works out which
surfaces it can walk, climb and fit under. The walkable surface is shrunk by the agent's radius, so every route already
keeps that clearance from the walls instead of hugging them.
A baked mesh answers path(start, goal), the same contract the nav grid offers, so steering's navigate behaviour
takes either without knowing which: swap a grid for a mesh and no steering code changes. A goal it cannot reach gives
an empty route, or with partial the route to the nearest point it can reach. nearest snaps a point onto the mesh,
searching a tall, narrow box so a point at ground level finds an elevated platform and a point beside a wall lands on
the floor rather than through it. randomPoint picks a spot on the walkable surface, which is the fix for patrol AI
that wanders into scenery.
For dense groups, mesh.crowd hands movement to Recast's own crowd simulation. You add agents with their radius,
speed and acceleration, send each one to a goal, and read back its position and velocity. The mesh steps its crowds on
the simulation step, so agents move at the same speed on any screen.
Features
- Real geometry — bridges, ramps, arches, overhangs and a floor above a floor, from your level's triangles.
- Terrain baking — triangulate and bake a height function's region in one call.
- Clearance built in — the mesh is eroded by the agent's radius at bake time.
- One path contract — the same
path(start, goal)as the grid tier, so steering takes either. - Reachable random points —
randomPointfor wander and patrol goals. - Snapping —
nearestfinds the mesh under or beside any point. - Crowds — Recast's crowd tier, with per-agent radius, height, speed and acceleration.
- Units you know — head-room, climb and radius in world units, converted to voxels safely: climb rounded down, radius rounded up.
- Embedded core — standalone builds carry the Recast core inside the game, with nothing extra to host.
Good for
- 3D action and adventure levels with bridges, balconies, ramps and stairs.
- Shooters with multi-level maps, where enemies must find the stairs to reach the player.
- Patrol and wander AI that should never pick a goal inside a wall.
- Dense crowds of agents in a plaza or a corridor that must not pass through one another.
- Terrain worlds where a grid would approximate cliffs and pillars too coarsely.
Make it yours
The bake takes either positions and indices or a terrain region (its height function, size, resolution and centre), the voxel resolution, and the agent's radius, height, highest climbable step and steepest slope. Each crowd takes a maximum agent count and the widest agent it will hold, and each agent its own radius, height, speed, acceleration and Recast's avoidance settings, so a slow heavy unit and a quick small one can share a crowd.
Two different uses: a castle level baked from its geometry where guards plan with path and are moved by steering,
patrolling between randomPoint goals along the walls and over the drawbridge; and a station concourse where 64
commuters form a crowd, each sent to a platform and copied back onto its model every frame.
A quick look
Bake a mesh, plan a route, and move a crowd:
const mesh = await game.navMesh.bake({ positions, indices, agentRadius: 0.5 });
const route = mesh.path(unit, target); // the same contract nav's grid uses
const goal = mesh.randomPoint(); // guaranteed reachable
const crowd = mesh.crowd({ maxAgents: 64 });
const id = crowd.add(spawnPoint, { radius: 0.5, maxSpeed: 4 });
crowd.goto(id, exit);
const at = crowd.position(id), heading = crowd.velocity(id); // copy these onto your object
Works with
nav— the grid tier: instant, no bake, and the right choice for open ground and simple obstacles.steering— moves bodies along mesh routes with avoidance, flocking and arrival; most games use it rather than a crowd.terrain-3d— the height function a terrain bake reads.world-3d— the 3D world the agents walk, though the mesh needs no world of its own.
Good to know
- Baking is a load-time job: re-bake rather than edit. There is no dynamic carving, so a door that closes wants a grid or a second mesh.
- One mesh is one tile and serves one agent radius; a second size of walker needs a second bake, and a very large world is best baked in regions.
- Triangles must be wound counter-clockwise seen from above, or the mesh bakes to nothing.
- A crowd's
maxAgents(256 by default) is a hard cap, and agents in different crowds do not see each other. - Crowd agents are Recast's simulation, read back rather than driven by your movement code.
Changes
3.0.0-5 (2026-10-26)
- Changed: the
modulebake option only loads the core from the game's own origin; a URL on another origin, or adata:URL, is refused. Standalone builds embed the core and are unaffected.






