# Movement API

## Change Wander Type

Changes the AI's Wander Type. If the Dynamic Wander Type is used, the AI's current position will be updated as the AI's new starting position, which is used by the Dynamic Wander position.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.ChangeWanderType(EmeraldSystem EmeraldComponent, EmeraldMovement.WanderTypes NewWanderType)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.ChangeWanderType(EmeraldComponent,  EmeraldMovement.WanderTypes.Dynamic);
```

{% endcode %}

## Update Dynamic Wander Position

Updates the AI's dynamic wandering position to the AI's current position.

<pre class="language-csharp" data-full-width="false"><code class="lang-csharp"><strong>EmeraldAPI.Movement.UpdateDynamicWanderPosition(EmeraldSystem EmeraldComponent)
</strong></code></pre>

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.UpdateDynamicWanderPosition(EmeraldComponent);
```

{% endcode %}

## Set Dynamic Wander Position

Sets the AI's dynamic wandering position to the position of the Destination. This is useful for functionality such as custom AI schedules. Note: This will automatically change your AI's Wander Type to Dynamic.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.SetDynamicWanderPosition(EmeraldSystem EmeraldComponent, Vector3 DestinationPosition)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.SetDynamicWanderPosition(EmeraldComponent, YourVector3Position);
```

{% endcode %}

## Update Starting Position

Updates the AI's starting position to the AI's current position.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.UpdateStartingPosition(EmeraldSystem EmeraldComponent)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.UpdateStartingPosition(EmeraldComponent);
```

{% endcode %}

## Set Custom Destination

Overrides the AI's Wander Type to Custom and sets the AI's destination to the Vector3 position. This is useful for functionality like point and click movement, schedules, and more. Because this modifies the AI's Wander Type, the ChangeWanderType function will need to be called again to set the desired Wander Type, if something other than Custom is wanted.

<pre class="language-csharp" data-full-width="false"><code class="lang-csharp"><strong>EmeraldAPI.Movement.SetCustomDestination(EmeraldSystem EmeraldComponent, Vector3 DestinationPosition)
</strong></code></pre>

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.SetCustomDestination(EmeraldComponent, YourVector3Position);
```

{% endcode %}

## Set Destination

Sets the AI's destination to the Vector3 position. Note: It is recommended that SetCustomDestination is used (when possible) as an AI will still attempt to use their Generated Wander Type position.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.SetDestination(EmeraldSystem EmeraldComponent, Vector3 DestinationPosition)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.SetDestination(EmeraldComponent, YourVector3Position);
```

{% endcode %}

## Generate Random Destination

Generates a new position to move to within the specified radius based on the AI's current position.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.GenerateRandomDestination(EmeraldSystem EmeraldComponent, int Radius)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.GenerateRandomDestination(EmeraldComponent, 10);
```

{% endcode %}

## Add Waypoint

Adds a waypoint to an AI's Waypoint List.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.AddWaypoint(EmeraldSystem EmeraldComponent, Transform Waypoint)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.AddWaypoint(EmeraldComponent, YourWaypointTransform);
```

{% endcode %}

## Remove Waypoint

Removes a waypoint from the AI's Waypoint List according to the specified index.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.RemoveWaypoint(EmeraldSystem EmeraldComponent, int WaypointIndex)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.RemoveWaypoint(EmeraldComponent, YourWaypointIndexNumber);
```

{% endcode %}

## Clear All Waypoints

Clears all of an AI's current waypoints. Note: When an AI's waypoints are cleared, it will be set to the Stationary wander type to avoid an error. If you want the AI to follow newly created waypoints, you will need to set it's Wander Type back to Waypoint with the ChangeWanderType function (located at EmeraldAPI.Movement.ChangeWanderType).

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.ClearAllWaypoints(EmeraldSystem EmeraldComponent)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.ClearAllWaypoints(EmeraldComponent);
```

{% endcode %}

## Stop Movement

Stops an AI from moving when out of combat. This is useful for functionality like dialogue.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.StopMovement(EmeraldSystem EmeraldComponent)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.StopMovement(EmeraldComponent);
```

{% endcode %}

## Resume Movement

Resumes an AI's movement after using the StopMovement function.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.ResumeMovement(EmeraldSystem EmeraldComponent)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.ResumeMovement(EmeraldComponent);
```

{% endcode %}

## Stop Following

Stops an AI with a follow target from following. This will only work if an AI has a Current Follow Target.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.StopFollowing(EmeraldSystem EmeraldComponent)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.StopFollowing(EmeraldComponent);
```

{% endcode %}

## Resume Following

Allows an AI with a follow target to resume following its follower. This will only work if an AI has a Current Follow Target.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.ResumeFollowing(EmeraldSystem EmeraldComponent)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.ResumeFollowing(EmeraldComponent);
```

{% endcode %}

## Start Companion Guard Position

Allows a Companion AI (an AI with Follow Target) to guard the assigned position.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.StartCompanionGuardPosition(EmeraldSystem EmeraldComponent, Vector3 PositionToGuard)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.StartCompanionGuardPosition(EmeraldComponent, YourPositionToGuard);
```

{% endcode %}

## Stop Companion Guard Position

Stops a Companion AI (an AI with Follow Target) from guarding and returns it to their current follower.

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.StopCompanionGuardPosition(EmeraldSystem EmeraldComponent)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.StopCompanionGuardPosition(EmeraldComponent);
```

{% endcode %}

## Rotate Towards Position

Rotates the AI towards the specified target position using the AI's turning animations. The angle in which the AI will stop rotating is based off of an AI's Turning Angle set within the [Movement Component](/emerald-ai-wiki/emerald-components-required/movement-component.md) editor. The AI will be unable to move during the duration of the turning process. If an AI is wandering, it is recommended that StopMovement is called first to stop an AI from wandering as an AI can still wander after the rotating has finished.&#x20;

{% hint style="info" %}
**Note:** The TargetPosition can be an object, a player, another AI, a custom position, etc.
{% endhint %}

{% code fullWidth="false" %}

```csharp
EmeraldAPI.Movement.RotateTowardsPosition(EmeraldSystem EmeraldComponent, Vector3 TargetPosition)
```

{% endcode %}

{% code fullWidth="false" %}

```csharp
//Example - It is recomended that EmeraldComponent is cached somewhere
EmeraldSystem EmeraldComponent = GetComponent<EmeraldSystem>();
EmeraldAPI.Movement.RotateTowardsPosition(EmeraldComponent, YourTargetPosition);
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://black-horizon-studios.gitbook.io/emerald-ai-wiki/api/available-api/movement-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
