# VectorUtils

This class provides additional functionality for working with Vector3 vectors.

### Available methods

```csharp
public static float Distance(this Vector3 from, Vector3 to)
```

*This method returns distance between two positions.*

***

```csharp
public static float DistanceXZ(this Vector3 from, Vector3 to)
```

*This method returns 2D distance between two given 3D positions (in XZ plane, ignoring Y).*

<pre class="language-csharp"><code class="lang-csharp"><strong>public static float DistanceZX(Vector3 from, Vector3 to)
</strong></code></pre>

*This method returns 2D distance between two given 3D positions (in XZ plane, ignoring Y).*

{% hint style="info" %}
These 2 methods could be useful for getting distance between characters in top-down or strategy games, ignoring height of that characters.
{% endhint %}

***

```csharp
public static Vector3 GetRandomPosition(Vector3 minPosition, Vector3 maxPosition)
```

*This method generates random position inside of cube represented by two given positions (min and max).*

***

```csharp
public static Vector3 ClosestPointOnMeshOBB(MeshFilter meshFilter, Vector3 worldPoint)
```

*This method returns the closest point on given mesh, from certain world point.*

*Example:*

```csharp
// Imaginary laser shot from muzzle to closest point on target obstacle mesh
Vector3 shootPoint = VectorUtils.ClosestPointOnMeshOBB(obstacleMesh, muzzlePos);

laser.SetPositions(muzzlePos, shootPoint);
```

***

```csharp
public static bool IsObjectInCone(Transform targetObj, Transform lookFromTransform, float coneAngle)
```

*This method helps to detect if certain transform situated inside the given cone. It could be useful for enemies detection by AI bots.*

*Example:*

```csharp
if (VectorUtils.IsObjectInCone(enemyTransform, botHead, 60f))
{
    Debug.Log("I see you!");
}
```
