menu_bookDocumentation
NavMesh Agent: AI Pathfinding Component with Crowd Control
The s&box NavMeshAgent component moves GameObjects along the NavMesh automatically with built-in crowd control to avoid collisions between agents.
Component Setup
Add the NavMeshAgent component to a GameObject. It takes over control of position and rotation. Create a separate AI logic component that sets target positions and animates based on agent velocity.
Code API
CSHARP
NavMeshAgent agent = Components.Get<NavMeshAgent>();
// Set target position — agent will pathfind there until stopped
agent.MoveTo( targetPosition );
// Stop moving
agent.Stop();
// Read the agent's current velocity (useful for animation)
var velocity = agent.Velocity;Usage Pattern
Typically you create a custom AI component alongside the NavMeshAgent that:
- Sets target positions via MoveTo()
- Reads agent.Velocity to drive animation parameters
- Adjusts max speed and acceleration as the agent reaches goals
- Handles state transitions (patrol, chase, idle)
The crowd control system automatically handles multiple agents navigating to the same target without overlapping.
Was this helpful?