I'm using Unity and Vector struct.
I use Vector3.Distance(a, b) function a lot, but I've just noticed that I want a slightly modified version of it which ignores the Y component and gives the distance in horizontal space. Lets call it a Vector3.HorizontalDistance(a, b).
float distance = Vector3.Distance(position1, position2);
float horizontalDistance = Vector3.HorizontalDistance(position1, position2); //I want this
The horizontal distance method should look like this
public static float HorizontalDistance(Vector3 pos1, Vector3 pos2)
{
pos1.y = 0f;
pos2.y = 0f;
return Vector3.Distance(pos1, pos2);
}
Right now I put this method in my Utils class and call it like this
float distance = Utils.HorizontalDistance(position1, position2);
But it doesn't feel right, it seems out of context without Vector3 name in in, I want to extend the Vector3's functionality and call it like this
Vector3.HorizontalDistance(a, b);
BUT I don't know how to do that, I couldn't find any information on this subject.?