Breakroom is now Sinewave Campus. Book a meeting

SNavMeshAgent

ClientComponents
On this classGetAreaCost
  1. Functions
  2. GetAreaCost
  3. Move
  4. Resume
  5. SetAreaCost
  6. Stop
  7. SetDestination
  8. Warp
  9. Properties
  10. Enabled
  11. Accelleration
  12. AngularSpeed
  13. AreaMask
  14. AutoRepath
  15. AutoBraking
  16. AutoTraverseOffMeshLink
  17. AvoidancePriority
  18. BaseOffset
  19. DesiredVelocity
  20. Destination
  21. HasPath
  22. Height
  23. IsOnNavMesh
  24. IsOnOffMeshLink
  25. IsPathStale
  26. NextPosition
  27. PathEndPosition
  28. PathPending
  29. Radius
  30. RemainingDistance
  31. Speed
  32. SteeringTarget
  33. StoppingDistance
  34. UpdatePosition
  35. UpdateRotation
  36. Velocity
  37. GameObject
Members 35
FunctionGetAreaCost–
FunctionMoveApply relative movement to current position.
FunctionResumeResume the NavMesh agent.
FunctionSetAreaCostSets the cost for traversing over areas of the area type.
FunctionStopTo stop the NavMesh agent.
FunctionSetDestinationSet or update the destination.
FunctionWarpWarp to the position you want, also you can set agent's world position and vector to make this act as Move(SVector position).
PropertyEnabledEnable or disable this component.
PropertyAccellerationThe maximum acceleration of an agent as it follows a path.
PropertyAngularSpeedMaximum turning speed in while following a path.
PropertyAreaMaskSpecifies which NavMesh area is passable.
PropertyAutoRepathSet the agent attempt to acquire a new path if the existing path becomes invalid.
PropertyAutoBrakingSet the agent brake automatically to avoid overshooting the destination point.
PropertyAutoTraverseOffMeshLinkSet the agent move across OffMeshLinks automatically.
PropertyAvoidancePriorityThe avoidance priority level.
PropertyBaseOffsetThe relative vertical displacement of the GameObject.
PropertyDesiredVelocityThe desired velocity of the agent including any potential contribution from avoidance.
PropertyDestinationThe desired velocity of the agent including any potential contribution from avoidance.
PropertyHasPathDoes the agent currently have a path?
PropertyHeightThe height of the agent for purposes of passing under obstacles, etc.
PropertyIsOnNavMeshIs the agent currently bound to the navmesh?
PropertyIsOnOffMeshLinkIs the agent currently positioned on an OffMeshLink?
PropertyIsPathStaleIs the current path stale?
PropertyNextPositionGet or set the simulation position of the navmesh agent.
PropertyPathEndPositionEnd positon of navigation.
PropertyPathPendingIs a path in the process of being computed but not yet ready?
PropertyRadiusThe avoidance radius for the agent.
PropertyRemainingDistanceThe distance between the agent's position and the destination on the current path.
PropertySpeedMaximum movement speed when following a path.
PropertySteeringTargetGet the current steering target along the path.
PropertyStoppingDistanceStop within this distance from the target position.
PropertyUpdatePositionGet or set whether the transform position is synchronized with the simulated agent position.
PropertyUpdateRotationShould the agent update the transform orientation?
PropertyVelocityaccess the current velocity of the NavMeshAgent component, or set a velocity to control the agent manually.
PropertyGameObject–

Functions​

GetAreaCost​

float GetAreaCost(int areaIndex)

Parameters

NameTypeDefault
areaIndexint–

Returns

float

Example

Lua
floatCost = Space.Host.ExecutingObject.NavMeshAgent.GetAreaCost(1)

Move​

void Move(SVector movement)

Apply relative movement to current position.

Parameters

NameTypeDefault
movementSVector–

Returns

void

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.Move(Vector.New(2,0,0))

Resume​

void Resume()

Resume the NavMesh agent.

Returns

void

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.Resume()
Lua
agentobject = Space.Scene.Find("Cube")
agent = agentobject.NavMeshAgent
if agent == nil then
agent = Space.Scene.Find("Cube").AddNavMeshAgent()
end
counts = 0
--stop first, then resume.
function StopAndResume()
counts = counts +1
if counts > 10 then
agent.Stop()
end
if counts > 50 then
agent.Resume()
end
end
agentobject.SubscribeToEvents()
agentobject.OnUpdate(StopAndResume)
agent.Destination = Space.Scene.Find("TargetTransform").WorldPosition
--set destination.

SetAreaCost​

void SetAreaCost(int areaIndex, float cost)

Sets the cost for traversing over areas of the area type.

Parameters

NameTypeDefault
areaIndexint–
costfloat–

Returns

void

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.SetAreaCost(1, 10.0)

Stop​

void Stop()

To stop the NavMesh agent.

Returns

void

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.Stop()

SetDestination​

void SetDestination(SVector position)

Set or update the destination.

Parameters

NameTypeDefault
positionSVector–

Returns

void

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.SetDestination(Vector.New(10,0,0))

Warp​

void Warp(SVector position)

Warp to the position you want, also you can set agent's world position and vector to make this act as Move(SVector position).

Parameters

NameTypeDefault
positionSVector–

Returns

void

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.Warp(Vector.New(10,0,0))

Properties​

Enabled​

bool Enabled {get; set; }

Enable or disable this component.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.Enabled = false
Lua
--clicking this object will Enable/Disable it's Nav Mesh Agent component
thisGameObject = Space.Host.ExecutingObject
component = thisGameObject.NavMeshAgent

OnClick = function()
component.Enabled = not component.Enabled
end


thisGameObject.AddClickable()
thisGameObject.Clickable.OnClick(OnClick)

Accelleration​

float Accelleration {get; set; }

The maximum acceleration of an agent as it follows a path.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.Accelleration = 60

AngularSpeed​

float AngularSpeed {get; set; }

Maximum turning speed in while following a path.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.AngularSpeed = 60

AreaMask​

int AreaMask {get; set; }

Specifies which NavMesh area is passable.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.AreaMask = 3

AutoRepath​

bool AutoRepath {get; set; }

Set the agent attempt to acquire a new path if the existing path becomes invalid.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.AutoRepath = false

AutoBraking​

bool AutoBraking {get; set; }

Set the agent brake automatically to avoid overshooting the destination point.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.AutoBraking = false
bool AutoTraverseOffMeshLink {get; set; }

Set the agent move across OffMeshLinks automatically.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.AutoTraverseOffMeshLink = false

AvoidancePriority​

int AvoidancePriority {get; set; }

The avoidance priority level.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.AvoidancePriority = 10

BaseOffset​

float BaseOffset {get; set; }

The relative vertical displacement of the GameObject.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.BaseOffset = 3

DesiredVelocityRead only​

SVector DesiredVelocity {get; }

The desired velocity of the agent including any potential contribution from avoidance.

Example

Lua
vectorVelocity = Space.Host.ExecutingObject.NavMeshAgent.DesiredVelocity

Destination​

SVector Destination {get; set; }

The desired velocity of the agent including any potential contribution from avoidance.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.Destination = Vector.New(10,0,0)

HasPathRead only​

bool HasPath {get; }

Does the agent currently have a path?

Example

Lua
hasPath = Space.Host.ExecutingObject.NavMeshAgent.HasPath

Height​

float Height {get; set; }

The height of the agent for purposes of passing under obstacles, etc.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.Height = 5

IsOnNavMeshRead only​

bool IsOnNavMesh {get; }

Is the agent currently bound to the navmesh?

Example

Lua
isOn = Space.Host.ExecutingObject.NavMeshAgent.IsOnNavMesh
bool IsOnOffMeshLink {get; }

Is the agent currently positioned on an OffMeshLink?

Example

Lua
isOnOff = Space.Host.ExecutingObject.NavMeshAgent.IsOnOffMeshLink

IsPathStaleRead only​

bool IsPathStale {get; }

Is the current path stale?

Example

Lua
isStale = Space.Host.ExecutingObject.NavMeshAgent.IsPathStale

NextPosition​

SVector NextPosition {get; set; }

Get or set the simulation position of the navmesh agent.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.NextPosition = Vector.New(10, 0, 0)

PathEndPositionRead only​

SVector PathEndPosition {get; }

End positon of navigation.

Example

Lua
vectorPathEndPos = Space.Host.ExecutingObject.NavMeshAgent.PathEndPosition

PathPendingRead only​

bool PathPending {get; }

Is a path in the process of being computed but not yet ready?

Example

Lua
isPending = Space.Host.ExecutingObject.NavMeshAgent.PathPending

Radius​

float Radius {get; set; }

The avoidance radius for the agent.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.Radius = 5

RemainingDistanceRead only​

float RemainingDistance {get; }

The distance between the agent's position and the destination on the current path.

Example

Lua
vectorDist = Space.Host.ExecutingObject.NavMeshAgent.RemainingDistance

Speed​

float Speed {get; set; }

Maximum movement speed when following a path.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.Speed = 20

SteeringTargetRead only​

SVector SteeringTarget {get; }

Get the current steering target along the path.

Example

Lua
vectorSteeringTarget = Space.Host.ExecutingObject.NavMeshAgent.SteeringTarget

StoppingDistance​

float StoppingDistance {get; set; }

Stop within this distance from the target position.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.StoppingDistance = 2

UpdatePosition​

bool UpdatePosition {get; set; }

Get or set whether the transform position is synchronized with the simulated agent position.

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.UpdatePosition = true

UpdateRotation​

bool UpdateRotation {get; set; }

Should the agent update the transform orientation?

Example

Lua
Space.Host.ExecutingObject.NavMeshAgent.UpdateRotation = true

VelocityRead only​

SVector Velocity {get; }

access the current velocity of the NavMeshAgent component, or set a velocity to control the agent manually.

Example

Lua
vectorVelocity = Space.Host.ExecutingObject.NavMeshAgent.Velocity

GameObjectRead only​

SGameObject GameObject {get; }

Example

Lua
theGameObject = Space.Host.ExecutingObject.NavMeshAgent.GameObject