# Distance

> Calculates the minimum separation of this collider against another collider.

## Definition

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

## Distance(Collider2D)

Calculates the minimum separation of this collider against another collider.

```csharp
public ColliderDistance2D Distance(Collider2D collider)
```

### Parameters

**** (\[Collider2D]\(/engine/6000.0/script-reference/unityengine/collider2d)): A collider used to calculate the minimum separation against this collider.

### Returns

| Type                                                                                    | Description                                           |
| --------------------------------------------------------------------------------------- | ----------------------------------------------------- |
| [ColliderDistance2D](/engine/6000.0/script-reference/unityengine/colliderdistance2d.md) | The minimum separation of collider and this collider. |

### Remarks

A valid collider must be provided for the [ColliderDistance2D](/engine/6000.0/script-reference/unityengine/colliderdistance2d.md) to be valid.  If there are any problems with collider or this [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) such as they are disabled or do not contain any collision shapes then the separation will be invalid as indicated by [ColliderDistance2D.isValid](/engine/6000.0/script-reference/unityengine/colliderdistance2d/isvalid.md).

Additional Resources: [Physics2D.Distance](/engine/6000.0/script-reference/unityengine/physics2d/distance.md) and [Rigidbody2D.Distance](/engine/6000.0/script-reference/unityengine/rigidbody2d/distance.md).

## Distance(Vector2, float, Collider2D, Vector2, float)

A valid collider must be provided for the [ColliderDistance2D](/engine/6000.0/script-reference/unityengine/colliderdistance2d.md) to be valid. If there are any problems with collider or this [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) such as they are disabled or do not contain any collision shapes then the separation will be invalid as indicated by [ColliderDistance2D.isValid](/engine/6000.0/script-reference/unityengine/colliderdistance2d/isvalid.md).

```csharp
public ColliderDistance2D Distance(Vector2 thisPosition, float thisAngle, Collider2D collider, Vector2 position, float angle)
```

### Parameters

**** (\[Vector2]\(/engine/6000.0/script-reference/unityengine/vector2)): The position to use for this Collider.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The rotation to use for this Collider.**** (\[Collider2D]\(/engine/6000.0/script-reference/unityengine/collider2d)): A collider used to calculate the minimum separation against this Collider.**** (\[Vector2]\(/engine/6000.0/script-reference/unityengine/vector2)): The position to use for the specified collider.**** (\[float]\(https\://learn.microsoft.com/dotnet/api/system.single)): The rotation to use for the specified collider.

### Returns

| Type                                                                                    | Description                                           |
| --------------------------------------------------------------------------------------- | ----------------------------------------------------- |
| [ColliderDistance2D](/engine/6000.0/script-reference/unityengine/colliderdistance2d.md) | The minimum separation of collider and this collider. |

### Remarks

A valid collider must be provided for the [ColliderDistance2D](/engine/6000.0/script-reference/unityengine/colliderdistance2d.md) to be valid.  If there are any problems with collider or this [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) such as they are disabled or do not contain any collision shapes then the separation will be invalid as indicated by [ColliderDistance2D.isValid](/engine/6000.0/script-reference/unityengine/colliderdistance2d/isvalid.md).

**NOTE**: The positions and angles used here represent the position of the [Rigidbody2D](/engine/6000.0/script-reference/unityengine/rigidbody2d.md) the respective [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) is attached to. If the [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) is offset from the center of mass then the [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) will use the same offset. This can be confusing so it is recommened that only [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) that align with the center of mass are used. If not then you must take this into account. If the [Collider2D](/engine/6000.0/script-reference/unityengine/collider2d.md) is not attached to a [Rigidbody2D](/engine/6000.0/script-reference/unityengine/rigidbody2d.md), this call cannot be used and will result in a warning.

Additional Resources: [Physics2D.Distance](/engine/6000.0/script-reference/unityengine/physics2d/distance.md) and [Rigidbody2D.Distance](/engine/6000.0/script-reference/unityengine/rigidbody2d/distance.md).
