The Clamp
method in the Vector3
struct is used to constrain each component of the vector to lie within the specified minimum and maximum bounds. This method ensures that the resulting vector's components do not exceed the specified limits.
The Clamp
method in the Vector3
struct is used to constrain each component of the vector to lie within the specified minimum and maximum bounds. This method ensures that the resulting vector's components do not exceed the specified limits.
To use the Clamp
method, call it on an instance of Vector3
and provide two Vector3
parameters representing the minimum and maximum bounds. The method will return a new Vector3
where each component is clamped between the corresponding components of the otherMin
and otherMax
vectors.
Vector3 vector = new Vector3(5, 10, 15); Vector3 minBounds = new Vector3(0, 0, 0); Vector3 maxBounds = new Vector3(10, 10, 10); Vector3 clampedVector = vector.Clamp(minBounds, maxBounds); // clampedVector will be (5, 10, 10)