Description
The ClampLength
method in the Vector3
struct is used to limit the length of a vector to a specified maximum value. If the vector's length exceeds the specified maxLength
, it will be scaled down to match the maximum length while maintaining its direction. If the vector's length is already less than or equal to maxLength
, it remains unchanged.
Usage
To use the ClampLength
method, call it on an instance of Vector3
and pass the desired maximum length as a parameter. This method returns a new Vector3
instance with the clamped length.
Example
Vector3 vector = new Vector3(3, 4, 0);
float maxLength = 5.0f;
Vector3 clampedVector = vector.ClampLength(maxLength);
// clampedVector will be (3, 4, 0) because its length is already 5, which is equal to maxLength.