Description
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, effectively clamping the vector within a defined range.
Usage
To use the Clamp
method, call it on a Vector3
instance, passing in two Vector3
parameters: otherMin
and otherMax
. These parameters represent the minimum and maximum bounds for the clamping operation.
Example usage:
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);
In this example, the Clamp
method will adjust the components of vector
to ensure they are within the range defined by minBounds
and maxBounds
.
Example
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)