# SNavMeshAgent

## Index

### Functions Index

| Function Name                                                    |
| ---------------------------------------------------------------- |
| float [**GetAreaCost** ](#getareacost)(int areaIndex)            |
| void [**Move** ](#move)(SVector movement)                        |
| void [**Resume** ](#resume)()                                    |
| void [**SetAreaCost** ](#setareacost)(int areaIndex, float cost) |
| void [**Stop** ](#stop)()                                        |
| void [**SetDestination** ](#setdestination)(SVector position)    |
| void [**Warp** ](#wrap)(SVector position)                        |

### Properties Index

| Property Name                                                            |
| ------------------------------------------------------------------------ |
| bool [**Enabled** ](#enabled)`get` `set`                                 |
| float [**Accelleration** ](#accelleration)`get` `set`                    |
| float [**AngularSpeed** ](#angularspeed)`get` `set`                      |
| int [**AreaMask** ](#areamask)`get` `set`                                |
| bool [**AutoRepath** ](#autorepath)`get` `set`                           |
| bool [**AutoBraking** ](#autobraking)`get` `set`                         |
| bool [**AutoTraverseOffMeshLink** ](#autotraverseoffmeshlink)`get` `set` |
| int [**AvoidancePriority** ](#avoidancepriority)`get` `set`              |
| float [**BaseOffset** ](#baseoffset)`get` `set`                          |
| SVector [**DesiredVelocity** ](#desiredvelocity)`get`                    |
| SVector [**Destination** ](#destination)`get` `set`                      |
| bool [**HasPath** ](#haspath)`get`                                       |
| float [**Height** ](#height)`get` `set`                                  |
| bool [**IsOnNavMesh** ](#isonnavmesh)`get`                               |
| bool [**IsOnOffMeshLink** ](#isonoffmeshlink)`get`                       |
| bool [**IsPathStale** ](#ispathstale)`get`                               |
| SVector [**NextPosition** ](#nextposition)`get` `set`                    |
| SVector [**PathEndPosition** ](#pathendposition)`get`                    |
| bool [**PathPending** ](#pathpending)`get`                               |
| float [**Radius** ](#radius)`get` `set`                                  |
| float [**RemainingDistance** ](#remainingdistance)`get`                  |
| float [**Speed** ](#speed)`get` `set`                                    |
| SVector [**SteeringTarget** ](#steeringtarget)`get`                      |
| float [**StoppingDistance** ](#stoppingdistance)`get` `set`              |
| bool [**UpdatePosition** ](#updateposition)`get` `set`                   |
| bool [**UpdateRotation** ](#updaterotation)`get` `set`                   |
| SVector [**Velocity** ](#velocity)`get`                                  |
| SGameObject [**GameObject** ](#gameobject)`get`                          |

## Functions

### GetAreaCost

float **GetAreaCost** (int areaIndex)

*Function Description*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
floatCost = Space.Host.ExecutingObject.NavMeshAgent.GetAreaCost(1)
```

{% endtab %}
{% endtabs %}

### Move

void **Move** ([SVector](https://docs.sine.space/scripting/client-scripting-api-reference/types/svector) movement)

*Apply relative movement to current position.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### Resume

void **Resume** ()

*Resume the NavMesh agent.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.Resume()
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```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.
```

{% endtab %}
{% endtabs %}

### SetAreaCost

void **SetAreaCost** (int areaIndex, float cost)

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

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.SetAreaCost(1, 10.0)
```

{% endtab %}
{% endtabs %}

### Stop

void **Stop** ()

*To stop the NavMesh agent.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.Stop()
```

{% endtab %}
{% endtabs %}

### SetDestination

void **SetDestination** ([SVector](https://docs.sine.space/scripting/client-scripting-api-reference/types/svector) position)

*Set or update the destination.*

| Parameter | Type | Description |
| --------- | ---- | ----------- |
|           |      |             |

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### Warp

void **Warp** ([SVector](https://docs.sine.space/scripting/client-scripting-api-reference/types/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).*

<table><thead><tr><th width="196">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td></td><td></td><td></td></tr></tbody></table>

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

## Properties

### Enabled

bool **Enabled** `get` `set`

*Enable or disable this component.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.Enabled = false
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Lua" %}

```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)
```

{% endtab %}
{% endtabs %}

### Accelleration

float **Accelleration** `get` `set`

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

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.Accelleration = 60
```

{% endtab %}
{% endtabs %}

### AngularSpeed

float **AngularSpeed** `get` `set`

*Maximum turning speed in while following a path.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.AngularSpeed = 60
```

{% endtab %}
{% endtabs %}

### AreaMask

int **AreaMask** `get` `set`

*Specifies which NavMesh area is passable.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.AreaMask = 3
```

{% endtab %}
{% endtabs %}

### AutoRepath

bool **AutoRepath** `get` `set`

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

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.AutoRepath = false
```

{% endtab %}
{% endtabs %}

### AutoBraking

bool **AutoBraking** `get` `set`

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

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.AutoBraking = false
```

{% endtab %}
{% endtabs %}

### AutoTraverseOffMeshLink

bool **AutoTraverseOffMeshLink** `get` `set`

*Set the agent move across OffMeshLinks automatically.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.AutoTraverseOffMeshLink = false
```

{% endtab %}
{% endtabs %}

### AvoidancePriority

int **AvoidancePriority** `get` `set`

*The avoidance priority level.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.AvoidancePriority = 10
```

{% endtab %}
{% endtabs %}

### BaseOffset

float **BaseOffset** `get` `set`

*The relative vertical displacement of the GameObject.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.BaseOffset = 3
```

{% endtab %}
{% endtabs %}

### DesiredVelocity

[SVector](https://docs.sine.space/scripting/client-scripting-api-reference/types/svector) **DesiredVelocity** `get`

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

{% tabs %}
{% tab title="Lua" %}

```lua
vectorVelocity = Space.Host.ExecutingObject.NavMeshAgent.DesiredVelocity
```

{% endtab %}
{% endtabs %}

### Destination

[SVector](https://docs.sine.space/scripting/client-scripting-api-reference/types/svector) **Destination** `get` `set`

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

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### HasPath

bool **HasPath** `get`

*Does the agent currently have a path?*

{% tabs %}
{% tab title="Lua" %}

```lua
hasPath = Space.Host.ExecutingObject.NavMeshAgent.HasPath
```

{% endtab %}
{% endtabs %}

### Height

float **Height** `get` `set`

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

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.Height = 5
```

{% endtab %}
{% endtabs %}

### IsOnNavMesh

bool **IsOnNavMesh** `get`

*Is the agent currently bound to the navmesh?*

{% tabs %}
{% tab title="Lua" %}

```lua
isOn = Space.Host.ExecutingObject.NavMeshAgent.IsOnNavMesh
```

{% endtab %}
{% endtabs %}

### IsOnOffMeshLink

bool **IsOnOffMeshLink** `get`

*Is the agent currently positioned on an OffMeshLink?*

{% tabs %}
{% tab title="Lua" %}

```lua
isOnOff = Space.Host.ExecutingObject.NavMeshAgent.IsOnOffMeshLink
```

{% endtab %}
{% endtabs %}

### IsPathStale

bool **IsPathStale** `get`

*Is the current path stale?*

{% tabs %}
{% tab title="Lua" %}

```lua
isStale = Space.Host.ExecutingObject.NavMeshAgent.IsPathStale
```

{% endtab %}
{% endtabs %}

### NextPosition

[SVector](https://docs.sine.space/scripting/client-scripting-api-reference/types/svector) **NextPosition** `get` `set`

*Get or set the simulation position of the navmesh agent.*

{% tabs %}
{% tab title="Lua" %}

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

{% endtab %}
{% endtabs %}

### PathEndPosition

[SVector](https://docs.sine.space/scripting/client-scripting-api-reference/types/svector) **PathEndPosition** `get`

*End positon of navigation.*

{% tabs %}
{% tab title="Lua" %}

```lua
vectorPathEndPos = Space.Host.ExecutingObject.NavMeshAgent.PathEndPosition
```

{% endtab %}
{% endtabs %}

### PathPending

bool **PathPending** `get`

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

{% tabs %}
{% tab title="Lua" %}

```lua
isPending = Space.Host.ExecutingObject.NavMeshAgent.PathPending
```

{% endtab %}
{% endtabs %}

### Radius

float **Radius** `get` `set`

*The avoidance radius for the agent.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.Radius = 5
```

{% endtab %}
{% endtabs %}

### RemainingDistance

float **RemainingDistance** `get`

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

{% tabs %}
{% tab title="Lua" %}

```lua
vectorDist = Space.Host.ExecutingObject.NavMeshAgent.RemainingDistance
```

{% endtab %}
{% endtabs %}

### Speed

float **Speed** `get` `set`

*Maximum movement speed when following a path.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.Speed = 20
```

{% endtab %}
{% endtabs %}

### SteeringTarget

[SVector](https://docs.sine.space/scripting/client-scripting-api-reference/types/svector) **SteeringTarget** `get`

*Get the current steering target along the path.*

{% tabs %}
{% tab title="Lua" %}

```lua
vectorSteeringTarget = Space.Host.ExecutingObject.NavMeshAgent.SteeringTarget
```

{% endtab %}
{% endtabs %}

### StoppingDistance

float **StoppingDistance** `get` `set`

*Stop within this distance from the target position.*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.StoppingDistance = 2
```

{% endtab %}
{% endtabs %}

### UpdatePosition

bool **UpdatePosition** `get` `set`

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

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.UpdatePosition = true
```

{% endtab %}
{% endtabs %}

### UpdateRotation

bool **UpdateRotation** `get` `set`

*Should the agent update the transform orientation?*

{% tabs %}
{% tab title="Lua" %}

```lua
Space.Host.ExecutingObject.NavMeshAgent.UpdateRotation = true
```

{% endtab %}
{% endtabs %}

### Velocity

[SVector](https://docs.sine.space/scripting/client-scripting-api-reference/types/svector) **Velocity** `get`

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

{% tabs %}
{% tab title="Lua" %}

```lua
vectorVelocity = Space.Host.ExecutingObject.NavMeshAgent.Velocity
```

{% endtab %}
{% endtabs %}

### GameObject

[SGameObject](https://docs.sine.space/scripting/client-scripting-api-reference/types/sgameobject) **GameObject** `get`

*Property Description*

{% tabs %}
{% tab title="Lua" %}

```lua
theGameObject = Space.Host.ExecutingObject.NavMeshAgent.GameObject
```

{% endtab %}
{% endtabs %}
