menu_bookDocumentation
Navigation: Recast NavMesh Generation and Pathfinding in s&box
s&box implements Recast Navigation (the industry standard used in Unreal, Unity, and Godot) for navmesh generation and navigation agents.
What is a NavMesh?
A simplified map of traversable areas built from the game's PhysicsWorld. It helps AI with pathfinding but lacks exact height information — use PhysicsWorld alongside NavMesh for precise ground placement.
Creating a NavMesh
Click the "Enable NavMesh" button in the s&box scene editor header. Toggle viewing the generated mesh with the adjacent button. The mesh updates live in the editor and is split into tiles (yellow lines = polygon boundaries, blue lines = tile boundaries).
NavMesh Settings
Adjust properties like slope steepness and physics object filtering via the pencil icon in the NavMesh header group.
Code API
Access via Scene.NavMesh:
CSHARP
// Random position on navmesh
var pos = Scene.NavMesh.GetRandomPoint();
// Random position within radius
var pos = Scene.NavMesh.GetRandomPoint( testposition, radius );
// Closest point on navmesh
var pos = Scene.NavMesh.GetClosestPoint( testposition );
// Closest edge
var pos = Scene.NavMesh.GetClosestEdge( testposition );
// Calculate path
var path = Scene.NavMesh.CalculatePath( new CalculatePathRequest()
{
Agent = Agent,
Start = WorldPosition,
Target = TargetWorldPosition
} );
if ( path.IsValid() ) { /* path.Status is Complete or Partial */ }
// Mark dirty for background rebuild
Scene.NavMesh.SetDirty();
Was this helpful?