NavMeshAgentclass

An agent that can navigate the navmesh defined in the scene.

objectComponentNavMeshAgent
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public sealed class Sandbox.NavMeshAgent : Sandbox.Component

Constructors1

Showing 1 constructors

Methods7

Showing 7 methods

public void CompleteLinkTraversal()PUBLIC

Finish link traversal, must be called after traversing a link if AutoTraverseLinks is false.

Returns:void

public Vector3 GetLookAhead(float distance)PUBLIC

Get a point on the current path, distance away from here. This is a simplified path so only includes the first few corners.

ParameterTypeDescription
distancefloat
Returns:Vector3

public Sandbox.Navigation.NavMeshPath GetPath()PUBLIC

Returns the agent's current path as a NavMeshPath. This is not free, so avoid calling it every frame.

Returns:NavMeshPathA NavMeshPath containing the agent's current path information.

public void MoveTo(Vector3 targetPosition)PUBLIC

Navigate to the position

ParameterTypeDescription
targetPositionVector3
Returns:void

public void SetAgentPosition(Vector3 position)PUBLIC

If you want to move the agent from one position to another

ParameterTypeDescription
positionVector3
Returns:void

public void SetPath(Sandbox.Navigation.NavMeshPath path)PUBLIC

Assigns a precalculated path for the agent to follow. The agent will attempt to follow the path, but may adjust its movement to avoid obstacles or other agents. If the path becomes invalid during navigation, it may be recalculated completely.

ParameterTypeDescription
pathNavMeshPath
Returns:void

public void Stop()PUBLIC

Stop moving, or whatever we're doing

Returns:void

Properties20

Showing 20 properties

public float Sandbox.NavMeshAgent.Acceleration { get; set; }PUBLICGETSET

The maximum acceleration a agent can have. This is how fast the agent can change its velocity. If you want snappy movement this should be as high or higher than `Sandbox.NavMeshAgent.MaxSpeed`.

Returns:float

public Vector3 Sandbox.NavMeshAgent.AgentPosition { get; set; }PUBLICGETSET

Updated with the agent's position, even if UpdatePosition is false

Returns:Vector3

public bool Sandbox.NavMeshAgent.AllowDefaultArea { get; set; }PUBLICGETSET

Is the agent allowed to travel on the default area?

Returns:bool

public System.Collections.Generic.HashSet`1<Sandbox.Engine.Resources.NavMeshAreaDefinition> Sandbox.NavMeshAgent.AllowedAreas { get; set; }PUBLICGETSET

What areas the agent is allowed to travel on. If empty, all areas are allowed.

Returns:HashSet<NavMeshAreaDefinition>

public System.Collections.Generic.HashSet`1<Sandbox.Engine.Resources.NavMeshAreaDefinition> Sandbox.NavMeshAgent.ForbiddenAreas { get; set; }PUBLICGETSET

What areas the agent is not allowed to travel on. If empty, no areas are forbidden.

Returns:HashSet<NavMeshAreaDefinition>

public float Sandbox.NavMeshAgent.Height { get; set; }PUBLICGETSET

Returns:float

public bool Sandbox.NavMeshAgent.IsNavigating { get; set; }PUBLICGETSET

Returns true if the agent is currently navigating to a target.

Returns:bool

public System.Action Sandbox.NavMeshAgent.LinkEnter { get; set; }PUBLICGETSET

Emitted when the agent enters a link.

Returns:Action

public System.Action Sandbox.NavMeshAgent.LinkExit { get; set; }PUBLICGETSET

Emitted when the agent exits a link.

Returns:Action

public float Sandbox.NavMeshAgent.MaxSpeed { get; set; }PUBLICGETSET

Returns:float

public float Sandbox.NavMeshAgent.Radius { get; set; }PUBLICGETSET

Returns:float

public float Sandbox.NavMeshAgent.Separation { get; set; }PUBLICGETSET

Gets or sets the separation factor used to control how strongly agents avoid crowding each other.

Returns:float

public bool Sandbox.NavMeshAgent.SyncAgentPosition { get; set; }PUBLICGETSETOBSOLETE

Obsolete: This API member is obsolete.

Returns:bool

public System.Nullable`1<Vector3> Sandbox.NavMeshAgent.TargetPosition { get; set; }PUBLICGETSET

Gets the current target position for the agent, if one is set.

Returns:Nullable<Vector3>

public bool Sandbox.NavMeshAgent.UpdatePosition { get; set; }PUBLICGETSETPER-FRAME

Set the Position of the GameObject to the agent position every frame. You can turn this off and handle it yourself by using the AgentPosition property.

Returns:bool

public bool Sandbox.NavMeshAgent.UpdateRotation { get; set; }PUBLICGETSETPER-FRAME

This will simply face the direction it is moving. It is not configurable on purpose, so you should really turn this off and be doing this yourself if you need it to do anything specific.

Returns:bool

public Vector3 Sandbox.NavMeshAgent.WishVelocity { get; set; }PUBLICGETSET

The velocity the agent would like to move at, you can pass this into a PlayerController.

Returns:Vector3

On this page

Constructorspublic NavMeshAgent()Methodspublic System.Void CompleteLinkTraversal()public Vector3 GetLookAhead(System.Single distance)public Sandbox.Navigation.NavMeshPath GetPath()public System.Void MoveTo(Vector3 targetPosition)public System.Void SetAgentPosition(Vector3 position)public System.Void SetPath(Sandbox.Navigation.NavMeshPath path)public System.Void Stop()Propertiespublic System.Single Sandbox.NavMeshAgent.Acceleration { get; set; }public Vector3 Sandbox.NavMeshAgent.AgentPosition { get; set; }public System.Boolean Sandbox.NavMeshAgent.AllowDefaultArea { get; set; }public System.Collections.Generic.HashSet`1<Sandbox.Engine.Resources.NavMeshAreaDefinition> Sandbox.NavMeshAgent.AllowedAreas { get; set; }public System.Boolean Sandbox.NavMeshAgent.AutoTraverseLinks { get; set; }public System.Collections.Generic.HashSet`1<Sandbox.Engine.Resources.NavMeshAreaDefinition> Sandbox.NavMeshAgent.ForbiddenAreas { get; set; }public System.Single Sandbox.NavMeshAgent.Height { get; set; }public System.Boolean Sandbox.NavMeshAgent.IsNavigating { get; set; }public System.Boolean Sandbox.NavMeshAgent.IsTraversingLink { get; set; }public System.Action Sandbox.NavMeshAgent.LinkEnter { get; set; }public System.Action Sandbox.NavMeshAgent.LinkExit { get; set; }public System.Single Sandbox.NavMeshAgent.MaxSpeed { get; set; }public System.Single Sandbox.NavMeshAgent.Radius { get; set; }public System.Single Sandbox.NavMeshAgent.Separation { get; set; }public System.Boolean Sandbox.NavMeshAgent.SyncAgentPosition { get; set; }public System.Nullable`1<Vector3> Sandbox.NavMeshAgent.TargetPosition { get; set; }public System.Boolean Sandbox.NavMeshAgent.UpdatePosition { get; set; }public System.Boolean Sandbox.NavMeshAgent.UpdateRotation { get; set; }public Vector3 Sandbox.NavMeshAgent.Velocity { get; set; }public Vector3 Sandbox.NavMeshAgent.WishVelocity { get; set; }Metadata