# SNavMeshAgent

**Membres** 35

|           |                                                     |                                                                                                                               |
| --------- | --------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| Fonction  | [GetAreaCost](#getareacost)                         | –                                                                                                                             |
| Fonction  | [Move](#move)                                       | Apply relative movement to current position.                                                                                  |
| Fonction  | [Resume](#resume)                                   | Resume the NavMesh agent.                                                                                                     |
| Fonction  | [SetAreaCost](#setareacost)                         | Sets the cost for traversing over areas of the area type.                                                                     |
| Fonction  | [Stop](#stop)                                       | To stop the NavMesh agent.                                                                                                    |
| Fonction  | [SetDestination](#setdestination)                   | Set or update the destination.                                                                                                |
| Fonction  | [Warp](#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). |
| Propriété | [Enabled](#enabled)                                 | Enable or disable this component.                                                                                             |
| Propriété | [Accelleration](#accelleration)                     | The maximum acceleration of an agent as it follows a path.                                                                    |
| Propriété | [AngularSpeed](#angularspeed)                       | Maximum turning speed in while following a path.                                                                              |
| Propriété | [AreaMask](#areamask)                               | Specifies which NavMesh area is passable.                                                                                     |
| Propriété | [AutoRepath](#autorepath)                           | Set the agent attempt to acquire a new path if the existing path becomes invalid.                                             |
| Propriété | [AutoBraking](#autobraking)                         | Set the agent brake automatically to avoid overshooting the destination point.                                                |
| Propriété | [AutoTraverseOffMeshLink](#autotraverseoffmeshlink) | Set the agent move across OffMeshLinks automatically.                                                                         |
| Propriété | [AvoidancePriority](#avoidancepriority)             | The avoidance priority level.                                                                                                 |
| Propriété | [BaseOffset](#baseoffset)                           | The relative vertical displacement of the GameObject.                                                                         |
| Propriété | [DesiredVelocity](#desiredvelocity)                 | The desired velocity of the agent including any potential contribution from avoidance.                                        |
| Propriété | [Destination](#destination)                         | The desired velocity of the agent including any potential contribution from avoidance.                                        |
| Propriété | [HasPath](#haspath)                                 | Does the agent currently have a path?                                                                                         |
| Propriété | [Height](#height)                                   | The height of the agent for purposes of passing under obstacles, etc.                                                         |
| Propriété | [IsOnNavMesh](#isonnavmesh)                         | Is the agent currently bound to the navmesh?                                                                                  |
| Propriété | [IsOnOffMeshLink](#isonoffmeshlink)                 | Is the agent currently positioned on an OffMeshLink?                                                                          |
| Propriété | [IsPathStale](#ispathstale)                         | Is the current path stale?                                                                                                    |
| Propriété | [NextPosition](#nextposition)                       | Get or set the simulation position of the navmesh agent.                                                                      |
| Propriété | [PathEndPosition](#pathendposition)                 | End positon of navigation.                                                                                                    |
| Propriété | [PathPending](#pathpending)                         | Is a path in the process of being computed but not yet ready?                                                                 |
| Propriété | [Radius](#radius)                                   | The avoidance radius for the agent.                                                                                           |
| Propriété | [RemainingDistance](#remainingdistance)             | The distance between the agent's position and the destination on the current path.                                            |
| Propriété | [Speed](#speed)                                     | Maximum movement speed when following a path.                                                                                 |
| Propriété | [SteeringTarget](#steeringtarget)                   | Get the current steering target along the path.                                                                               |
| Propriété | [StoppingDistance](#stoppingdistance)               | Stop within this distance from the target position.                                                                           |
| Propriété | [UpdatePosition](#updateposition)                   | Get or set whether the transform position is synchronized with the simulated agent position.                                  |
| Propriété | [UpdateRotation](#updaterotation)                   | Should the agent update the transform orientation?                                                                            |
| Propriété | [Velocity](#velocity)                               | access the current velocity of the NavMeshAgent component, or set a velocity to control the agent manually.                   |
| Propriété | [GameObject](#gameobject)                           | –                                                                                                                             |

## Fonctions

### GetAreaCost

float GetAreaCost(int areaIndex)

Paramètres

| Nom       | Type | Valeur par défaut |
| --------- | ---- | ----------------- |
| areaIndex | int  | –                 |

Valeurs de retour

`float`

Exemple

**Lua**

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

```

### Move

void Move([SVector](/docs/fr/scripting/client-scripting-api-reference/types/svector.md) movement)

Apply relative movement to current position.

Paramètres

| Nom      | Type                                                                          | Valeur par défaut |
| -------- | ----------------------------------------------------------------------------- | ----------------- |
| movement | [SVector](/docs/fr/scripting/client-scripting-api-reference/types/svector.md) | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

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

```

### Resume

void Resume()

Resume the NavMesh agent.

Valeurs de retour

`void`

Exemple

**Lua**

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

```

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

```

### SetAreaCost

void SetAreaCost(int areaIndex, float cost)

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

Paramètres

| Nom       | Type  | Valeur par défaut |
| --------- | ----- | ----------------- |
| areaIndex | int   | –                 |
| cost      | float | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

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

```

### Stop

void Stop()

To stop the NavMesh agent.

Valeurs de retour

`void`

Exemple

**Lua**

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

```

### SetDestination

void SetDestination([SVector](/docs/fr/scripting/client-scripting-api-reference/types/svector.md) position)

Set or update the destination.

Paramètres

| Nom      | Type                                                                          | Valeur par défaut |
| -------- | ----------------------------------------------------------------------------- | ----------------- |
| position | [SVector](/docs/fr/scripting/client-scripting-api-reference/types/svector.md) | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

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

```

### Warp

void Warp([SVector](/docs/fr/scripting/client-scripting-api-reference/types/svector.md) 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).

Paramètres

| Nom      | Type                                                                          | Valeur par défaut |
| -------- | ----------------------------------------------------------------------------- | ----------------- |
| position | [SVector](/docs/fr/scripting/client-scripting-api-reference/types/svector.md) | –                 |

Valeurs de retour

`void`

Exemple

**Lua**

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

```

## Propriétés

### Enabled

bool Enabled {get; set; }

Enable or disable this component.

Exemple

**Lua**

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

```

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

```

### Accelleration

float Accelleration {get; set; }

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

Exemple

**Lua**

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

```

### AngularSpeed

float AngularSpeed {get; set; }

Maximum turning speed in while following a path.

Exemple

**Lua**

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

```

### AreaMask

int AreaMask {get; set; }

Specifies which NavMesh area is passable.

Exemple

**Lua**

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

Exemple

**Lua**

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

```

### AutoBraking

bool AutoBraking {get; set; }

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

Exemple

**Lua**

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

```

### AutoTraverseOffMeshLink

bool AutoTraverseOffMeshLink {get; set; }

Set the agent move across OffMeshLinks automatically.

Exemple

**Lua**

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

```

### AvoidancePriority

int AvoidancePriority {get; set; }

The avoidance priority level.

Exemple

**Lua**

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

```

### BaseOffset

float BaseOffset {get; set; }

The relative vertical displacement of the GameObject.

Exemple

**Lua**

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

```

### DesiredVelocity

[SVector](/docs/fr/scripting/client-scripting-api-reference/types/svector.md) DesiredVelocity {get; }

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

Exemple

**Lua**

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

```

### Destination

[SVector](/docs/fr/scripting/client-scripting-api-reference/types/svector.md) Destination {get; set; }

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

Exemple

**Lua**

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

```

### HasPath

bool HasPath {get; }

Does the agent currently have a path?

Exemple

**Lua**

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

```

### Height

float Height {get; set; }

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

Exemple

**Lua**

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

```

### IsOnNavMesh

bool IsOnNavMesh {get; }

Is the agent currently bound to the navmesh?

Exemple

**Lua**

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

```

### IsOnOffMeshLink

bool IsOnOffMeshLink {get; }

Is the agent currently positioned on an OffMeshLink?

Exemple

**Lua**

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

```

### IsPathStale

bool IsPathStale {get; }

Is the current path stale?

Exemple

**Lua**

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

```

### NextPosition

[SVector](/docs/fr/scripting/client-scripting-api-reference/types/svector.md) NextPosition {get; set; }

Get or set the simulation position of the navmesh agent.

Exemple

**Lua**

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

```

### PathEndPosition

[SVector](/docs/fr/scripting/client-scripting-api-reference/types/svector.md) PathEndPosition {get; }

End positon of navigation.

Exemple

**Lua**

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

```

### PathPending

bool PathPending {get; }

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

Exemple

**Lua**

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

```

### Radius

float Radius {get; set; }

The avoidance radius for the agent.

Exemple

**Lua**

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

```

### RemainingDistance

float RemainingDistance {get; }

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

Exemple

**Lua**

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

```

### Speed

float Speed {get; set; }

Maximum movement speed when following a path.

Exemple

**Lua**

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

```

### SteeringTarget

[SVector](/docs/fr/scripting/client-scripting-api-reference/types/svector.md) SteeringTarget {get; }

Get the current steering target along the path.

Exemple

**Lua**

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

```

### StoppingDistance

float StoppingDistance {get; set; }

Stop within this distance from the target position.

Exemple

**Lua**

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

Exemple

**Lua**

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

```

### UpdateRotation

bool UpdateRotation {get; set; }

Should the agent update the transform orientation?

Exemple

**Lua**

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

```

### Velocity

[SVector](/docs/fr/scripting/client-scripting-api-reference/types/svector.md) Velocity {get; }

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

Exemple

**Lua**

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

```

### GameObject

[SGameObject](/docs/fr/scripting/client-scripting-api-reference/types/sgameobject.md) GameObject {get; }

Exemple

**Lua**

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

```
