> For the complete documentation index, see [llms.txt](https://gley.gitbook.io/mobile-pedestrian-system/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gley.gitbook.io/mobile-pedestrian-system/complete-api/setdestination.md).

# SetDestination

### Description

Calculates a path from the current position of the pedestrian to a specified destination. The destination will be the closest waypoint to the destination point.

### Declaration

```csharp
public static void SetDestination(int pedestrianIndex, Vector3 position)
```

### Parameters

<table><thead><tr><th width="261">Name</th><th>Description</th></tr></thead><tbody><tr><td><strong>pedestrianIndex</strong></td><td>The index of the pedestrian.</td></tr><tr><td><strong>position</strong></td><td>The destination position.</td></tr></tbody></table>

### Example

```csharp
using Gley.PedestrianSystem;
using UnityEngine;
public class Test : MonoBehaviour
{
    // A reference to the pedestrian pool and player assigned in the inspector.
    public PedestrianPool pedestrianPool;
    public Transform player;

    void Start()
    {
        API.Initialize(player, 1, pedestrianPool);
        PedestrianEvents.onDestinationReached += DestinationReached;
    }

    public void SetDestination()
    {
        // Set a random destination.
        Vector3 destination = new Vector3(Random.Range(-500, 500), 0, Random.Range(-500, 500));

        // Make the vehicle with index 0 drive to the destination.
        API.SetDestination(0, destination);
    }

    private void DestinationReached(int pedestrianIndex)
    {
        if (pedestrianIndex == 0)
        {
            // Set another random destination for this vehicle if the previous one was reached.
            Vector3 destination = new Vector3(Random.Range(-500, 500), 0, Random.Range(-500, 500));
            API.SetDestination(pedestrianIndex, destination);
        }
    }

    private void OnDestroy()
    {
        PedestrianEvents.onDestinationReached -= DestinationReached;
    }
}

```
