codeAPI Reference
s&box NavigationLayer: NPC navigation
NPC behavior layer that handles navigation using NavMeshAgent. Provides movement commands and status tracking.
Properties
CSHARP
public NavMeshAgent Agent { get; private set; }
public Vector3? MoveTarget { get; private set; }
[Property]
public float StopDistance { get; private set; } = 10f;
/// Desired movement speed. Schedules can raise this to make the NPC run.
public float WishSpeed { get; set; } = 100f;Methods
CSHARP
/// Command this layer to move to a target.
public void MoveTo( Vector3 target, float stopDistance = 10f )
/// Current navigation status — reached target, still moving, or failed.
public TaskStatus GetStatus()
/// Reset navigation state.
public override void ResetLayer()Behavior
- Uses NavMeshAgent for pathfinding
- Updates animation based on agent velocity
- Returns TaskStatus.Success when within StopDistance
- Returns TaskStatus.Failed if agent stops navigating before reaching target
- Returns TaskStatus.Running while moving
Usage
Access via Npc.NavigationLayer. Call MoveTo() to set a destination, then poll GetStatus() to check progress. Raise WishSpeed to make the NPC run.
Example: A MoveTo task would call MoveTo() and return GetStatus() until Success.
Source
Used by NPC movement tasks and schedules.
Was this helpful?