Vector3 AddClamped( Vector3& toAdd, float maxLength )

book_4_sparkGenerated
code_blocksInput

Description

The AddClamped method adds a specified vector to the current vector, but ensures that the resulting vector's length does not exceed a specified maximum length. This is useful for operations where you want to add a vector but need to ensure the result stays within a certain magnitude.

Usage

To use the AddClamped method, call it on an instance of Vector3, passing in the vector to add and the maximum length as parameters. The method will return a new Vector3 that is the result of the addition, clamped to the specified maximum length.

Example

Vector3 currentVector = new Vector3(1, 2, 3);
Vector3 vectorToAdd = new Vector3(4, 5, 6);
float maxLength = 10.0f;

Vector3 result = currentVector.AddClamped(ref vectorToAdd, maxLength);
// result is a Vector3 that is the sum of currentVector and vectorToAdd, but clamped to a length of 10.0