Recast Navigation
Navigation-mesh Toolset for Games
|
Most modern, complex 3D games rely on navmeshes to drive their pathfinding and AI agent movement and navigation.
A navmesh is a simplified view of the traversable area of a game world, optimized for AI pathfiding and movement calculations. Navmeshes are usually built from the physics colliders of the world, since they define the areas an AI can legally exist.
Triangles in a navmesh represent nodes in the pathfinding graph, and edges between adjacent polygons define connections between these nodes. Pathfinding queries first construct a path consisting of a strip of adjacent polygons. This represents the "corridor" of space that leads the agent to their goal. That polygonal path is refined into sequence of line-segments through a string-pulling algorithm. Agents can then follow this sequence of waypoints to reach their goal.
A navmesh is usually tailored to a specific type of AI agent with a specific size and set of movement capabilities. After all, the areas that a huge ogre, or a medium human, or a tiny mouse can move in are very different. Because of this, it's often necessary to build multiple navmeshes for the same environment to accommodate different agent types.
AI size is the most important attribute and is defined in Recast as a radius and height. You can think of these values as representing either a cylinder or a capsule.
A maximum slope value defines the steepest angle geometry a character can walk. This helps ensure it doesn't try to walk up or down steep cliffs.
Finally, a maximum "step up" height defines the highest obstacle an AI agent can step up. This helps Recast know that an AI shouldn't get stuck thinking it can't step over a small curb or up a flight of stairs.
While a navmesh is a simplified version of a world's collision geometry, it is solving a fundamentally different problem. Very often, navmesh generation will sacrifice some accuracy in favor of geometry simplification. With navmesh pathfinding in games, it's more often than not better to have faster, slightly less accurate queries, than extremely-precise optimal paths.
For these reasons you should not use the navmesh or paths generated by the navmesh as collision geometry or animation splines. Detour provides an AI movement controller that demonstrates how path-following should work with the paths generated by navmesh path queries.
Recast is a set of tools for fully automating the navmesh building process, loading and streaming navmesh data, pathfidning and querying navmeshes at runtime, controlling AI agent movement, and more. It was originally created by Mikko Mononen in 2009 and has shipped in countless indie games, AAA titles, and commercial and open-source game engines such as Unity, Unreal, Godot, and O3DE.
Recast is roughly divided into two parts. "Recast" is the process that automates the navmesh building process, and is what most games and game engines use. "Detour" is the set of runtime systems for working with navmesh data, performing path queries, and controlling agent movement.
Recast builds navmeshes utilizing an mesh rasterization process. This process takes your input geometry, converts it to voxels, performs transformations to refine and filter the voxel data, and then re-triangulates voxels into an output navmesh. This has a number of benefits:
Recast showcases two approaches to building navmeshes in the "RecastDemo" project.
Sample_SoloMesh.cpp
shows the basics of building a single navmesh for a small game world. This process is the simplest version of working with Recast. The build process is outlined in Sample_SoloMesh::handleBuild
, but essentially breaks down to calling the following functions: