VectorUtils

This class provides additional functionality for working with Vector3 vectors.

Available methods

public static float DistanceZX(Vector3 from, Vector3 to)

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

This method could be useful for getting distance between characters in top-down or strategy games, ignoring height of that characters.


public static Vector3 GetRandomPosition(Vector3 minPosition, Vector3 maxPosition)

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


public static Vector3 ClosestPointOnMeshOBB(MeshFilter meshFilter, Vector3 worldPoint)

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

Example:

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

laser.SetPositions(muzzlePos, shootPoint);

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:

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

Last updated