Description
The DistanceSquared
method calculates the squared distance between the current Vector3
instance and a target Vector3
. This method is useful for performance optimization when you only need to compare distances, as it avoids the computational cost of a square root operation required by the Distance
method.
Usage
To use the DistanceSquared
method, call it on an instance of Vector3
and pass a reference to another Vector3
as the target. The method will return a float
representing the squared distance between the two vectors.
Example
Vector3 pointA = new Vector3(1, 2, 3);
Vector3 pointB = new Vector3(4, 5, 6);
float squaredDistance = pointA.DistanceSquared(ref pointB);
// squaredDistance now holds the value 27, which is the squared distance between pointA and pointB.