# Distance

> Calculates the distance between two three-dimensional points.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.7/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## Distance(Vector3, Vector3)

Calculates the distance between two three-dimensional points.

```csharp
public static float Distance(Vector3 a, Vector3 b)
```

### Parameters

**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The first three-dimensional point as a Vector3.**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The second three-dimensional point as a Vector3.

### Returns

| Type                                                          | Description                                     |
| ------------------------------------------------------------- | ----------------------------------------------- |
| [float](https://learn.microsoft.com/dotnet/api/system.single) | The scalar distance between points `a` and `b`. |

### Remarks

This method calculates the shortest distance between the two input points. Both points should be defined in the same coordinate space. `Vector3.Distance(a,b)` returns the same result as `(a-b).magnitude`. The resulting value is always >= 0.

### Examples

```csharp
using UnityEngine;

public class Vector3DistanceExample : MonoBehaviour
{
    // the first point is this transform's position
    public Transform other;

    void Start()
    {
        if (other)
        {
            // the second point is the position of the MonoBehaviour's transform
            float dist = Vector3.Distance(other.position, transform.position);
            print("Distance to other: " + dist);
        }
    }
}
```

## Distance(Vector3, Vector3)

Calculates the distance between two three-dimensional points.

```csharp
public static float Distance(in Vector3 a, in Vector3 b)
```

### Parameters

**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The first three-dimensional point as a Vector3.**** (\[Vector3]\(/engine/6000.7/script-reference/unityengine/vector3)): The second three-dimensional point as a Vector3.

### Returns

| Type                                                          | Description                                     |
| ------------------------------------------------------------- | ----------------------------------------------- |
| [float](https://learn.microsoft.com/dotnet/api/system.single) | The scalar distance between points `a` and `b`. |

### Remarks

This method calculates the shortest distance between the two input points. Both points should be defined in the same coordinate space. `Vector3.Distance(a,b)` returns the same result as `(a-b).magnitude`. The resulting value is always >= 0.

### Examples

```csharp
using UnityEngine;

public class Vector3DistanceExample : MonoBehaviour
{
    // the first point is this transform's position
    public Transform other;

    void Start()
    {
        if (other)
        {
            // the second point is the position of the MonoBehaviour's transform
            float dist = Vector3.Distance(other.position, transform.position);
            print("Distance to other: " + dist);
        }
    }
}
```
