SNavMeshAgent
On this classGetAreaCost
- Functions
- Get
Area Cost - Move
- Resume
- Set
Area Cost - Stop
- Set
Destination - Warp
- Properties
- Enabled
- Accelleration
- Angular
Speed - Area
Mask - Auto
Repath - Auto
Braking - Auto
Traverse Off Mesh Link - Avoidance
Priority - Base
Offset - Desired
Velocity - Destination
- Has
Path - Height
- Is
On Nav Mesh - Is
On Off Mesh Link - Is
Path Stale - Next
Position - Path
End Position - Path
Pending - Radius
- Remaining
Distance - Speed
- Steering
Target - Stopping
Distance - Update
Position - Update
Rotation - Velocity
- Game
Object
| Function | GetAreaCost | – |
| Function | Move | Apply relative movement to current position. |
| Function | Resume | Resume the NavMesh agent. |
| Function | SetAreaCost | Sets the cost for traversing over areas of the area type. |
| Function | Stop | To stop the NavMesh agent. |
| Function | SetDestination | Set or update the destination. |
| Function | Warp | Warp to the position you want, also you can set agent's world position and vector to make this act as Move(SVector position). |
| Property | Enabled | Enable or disable this component. |
| Property | Accelleration | The maximum acceleration of an agent as it follows a path. |
| Property | AngularSpeed | Maximum turning speed in while following a path. |
| Property | AreaMask | Specifies which NavMesh area is passable. |
| Property | AutoRepath | Set the agent attempt to acquire a new path if the existing path becomes invalid. |
| Property | AutoBraking | Set the agent brake automatically to avoid overshooting the destination point. |
| Property | AutoTraverseOffMeshLink | Set the agent move across OffMeshLinks automatically. |
| Property | AvoidancePriority | The avoidance priority level. |
| Property | BaseOffset | The relative vertical displacement of the GameObject. |
| Property | DesiredVelocity | The desired velocity of the agent including any potential contribution from avoidance. |
| Property | Destination | The desired velocity of the agent including any potential contribution from avoidance. |
| Property | HasPath | Does the agent currently have a path? |
| Property | Height | The height of the agent for purposes of passing under obstacles, etc. |
| Property | IsOnNavMesh | Is the agent currently bound to the navmesh? |
| Property | IsOnOffMeshLink | Is the agent currently positioned on an OffMeshLink? |
| Property | IsPathStale | Is the current path stale? |
| Property | NextPosition | Get or set the simulation position of the navmesh agent. |
| Property | PathEndPosition | End positon of navigation. |
| Property | PathPending | Is a path in the process of being computed but not yet ready? |
| Property | Radius | The avoidance radius for the agent. |
| Property | RemainingDistance | The distance between the agent's position and the destination on the current path. |
| Property | Speed | Maximum movement speed when following a path. |
| Property | SteeringTarget | Get the current steering target along the path. |
| Property | StoppingDistance | Stop within this distance from the target position. |
| Property | UpdatePosition | Get or set whether the transform position is synchronized with the simulated agent position. |
| Property | UpdateRotation | Should the agent update the transform orientation? |
| Property | Velocity | access the current velocity of the NavMeshAgent component, or set a velocity to control the agent manually. |
| Property | GameObject | – |
Functions
GetAreaCost
Parameters
| Name | Type | Default |
|---|---|---|
| areaIndex | int | – |
Returns
float
Example
floatCost = Space.Host.ExecutingObject.NavMeshAgent.GetAreaCost(1)
Move
Apply relative movement to current position.
Parameters
| Name | Type | Default |
|---|---|---|
| movement | SVector | – |
Returns
void
Example
Space.Host.ExecutingObject.NavMeshAgent.Move(Vector.New(2,0,0))
Resume
Resume the NavMesh agent.
Returns
void
Example
Space.Host.ExecutingObject.NavMeshAgent.Resume()
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
Sets the cost for traversing over areas of the area type.
Parameters
| Name | Type | Default |
|---|---|---|
| areaIndex | int | – |
| cost | float | – |
Returns
void
Example
Space.Host.ExecutingObject.NavMeshAgent.SetAreaCost(1, 10.0)
Stop
To stop the NavMesh agent.
Returns
void
Example
Space.Host.ExecutingObject.NavMeshAgent.Stop()
SetDestination
Set or update the destination.
Parameters
| Name | Type | Default |
|---|---|---|
| position | SVector | – |
Returns
void
Example
Space.Host.ExecutingObject.NavMeshAgent.SetDestination(Vector.New(10,0,0))
Warp
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
| Name | Type | Default |
|---|---|---|
| position | SVector | – |
Returns
void
Example
Space.Host.ExecutingObject.NavMeshAgent.Warp(Vector.New(10,0,0))
Properties
Enabled
Enable or disable this component.
Example
Space.Host.ExecutingObject.NavMeshAgent.Enabled = false
--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
The maximum acceleration of an agent as it follows a path.
Example
Space.Host.ExecutingObject.NavMeshAgent.Accelleration = 60
AngularSpeed
Maximum turning speed in while following a path.
Example
Space.Host.ExecutingObject.NavMeshAgent.AngularSpeed = 60
AreaMask
Specifies which NavMesh area is passable.
Example
Space.Host.ExecutingObject.NavMeshAgent.AreaMask = 3
AutoRepath
Set the agent attempt to acquire a new path if the existing path becomes invalid.
Example
Space.Host.ExecutingObject.NavMeshAgent.AutoRepath = false
AutoBraking
Set the agent brake automatically to avoid overshooting the destination point.
Example
Space.Host.ExecutingObject.NavMeshAgent.AutoBraking = false
AutoTraverseOffMeshLink
Set the agent move across OffMeshLinks automatically.
Example
Space.Host.ExecutingObject.NavMeshAgent.AutoTraverseOffMeshLink = false
AvoidancePriority
The avoidance priority level.
Example
Space.Host.ExecutingObject.NavMeshAgent.AvoidancePriority = 10
BaseOffset
The relative vertical displacement of the GameObject.
Example
Space.Host.ExecutingObject.NavMeshAgent.BaseOffset = 3
DesiredVelocityRead only
The desired velocity of the agent including any potential contribution from avoidance.
Example
vectorVelocity = Space.Host.ExecutingObject.NavMeshAgent.DesiredVelocity
Destination
The desired velocity of the agent including any potential contribution from avoidance.
Example
Space.Host.ExecutingObject.NavMeshAgent.Destination = Vector.New(10,0,0)
HasPathRead only
Does the agent currently have a path?
Example
hasPath = Space.Host.ExecutingObject.NavMeshAgent.HasPath
Height
The height of the agent for purposes of passing under obstacles, etc.
Example
Space.Host.ExecutingObject.NavMeshAgent.Height = 5
IsOnNavMeshRead only
Is the agent currently bound to the navmesh?
Example
isOn = Space.Host.ExecutingObject.NavMeshAgent.IsOnNavMesh
IsOnOffMeshLinkRead only
Is the agent currently positioned on an OffMeshLink?
Example
isOnOff = Space.Host.ExecutingObject.NavMeshAgent.IsOnOffMeshLink
IsPathStaleRead only
Is the current path stale?
Example
isStale = Space.Host.ExecutingObject.NavMeshAgent.IsPathStale
NextPosition
Get or set the simulation position of the navmesh agent.
Example
Space.Host.ExecutingObject.NavMeshAgent.NextPosition = Vector.New(10, 0, 0)
PathEndPositionRead only
End positon of navigation.
Example
vectorPathEndPos = Space.Host.ExecutingObject.NavMeshAgent.PathEndPosition
PathPendingRead only
Is a path in the process of being computed but not yet ready?
Example
isPending = Space.Host.ExecutingObject.NavMeshAgent.PathPending
Radius
The avoidance radius for the agent.
Example
Space.Host.ExecutingObject.NavMeshAgent.Radius = 5
RemainingDistanceRead only
The distance between the agent's position and the destination on the current path.
Example
vectorDist = Space.Host.ExecutingObject.NavMeshAgent.RemainingDistance
Speed
Maximum movement speed when following a path.
Example
Space.Host.ExecutingObject.NavMeshAgent.Speed = 20
SteeringTargetRead only
Get the current steering target along the path.
Example
vectorSteeringTarget = Space.Host.ExecutingObject.NavMeshAgent.SteeringTarget
StoppingDistance
Stop within this distance from the target position.
Example
Space.Host.ExecutingObject.NavMeshAgent.StoppingDistance = 2
UpdatePosition
Get or set whether the transform position is synchronized with the simulated agent position.
Example
Space.Host.ExecutingObject.NavMeshAgent.UpdatePosition = true
UpdateRotation
Should the agent update the transform orientation?
Example
Space.Host.ExecutingObject.NavMeshAgent.UpdateRotation = true
VelocityRead only
access the current velocity of the NavMeshAgent component, or set a velocity to control the agent manually.
Example
vectorVelocity = Space.Host.ExecutingObject.NavMeshAgent.Velocity
GameObjectRead only
Example
theGameObject = Space.Host.ExecutingObject.NavMeshAgent.GameObject



