# velocity

> Velocity at which the obstacle moves around the NavMesh.

## Definition

* **Type:** Property
* **Namespace:** [UnityEngine.AI](/engine/6000.6/script-reference/unityengine/ai.md)
* **Assembly:** UnityEngine.AIModule

```csharp
public Vector3 velocity { get; set; }
```

### Examples

```csharp
// Name this file (ManualObstacleVelocityUpdater.cs) to match the class name.
using System;
using UnityEngine;
using UnityEngine.AI;

/// <summary>
/// Update the current GameObject's NavMesh Obstacle velocity according to its position changes.
/// Useful when the position of an object is controlled by script.
/// </summary>
public class ManualObstacleVelocityUpdater : MonoBehaviour
{
    NavMeshObstacle m_Obstacle;
    Vector3 m_LastPosition;

    void Start()
    { 
        m_Obstacle = GetComponent<NavMeshObstacle>(); 
        m_LastPosition = transform.position; 
    }

    void Update()
    {
        var deltaTime = Time.deltaTime;
        if (m_Obstacle && deltaTime > Mathf.Epsilon)
        { 
            // Compute this frame's velocity 
            var newPosition = transform.position; 
            var velocity = (newPosition - m_LastPosition) / deltaTime; 
            m_Obstacle.velocity = velocity; 

            // Keep track of the last considered position 
            m_LastPosition = newPosition; 
        }
    }
}
```
