Vector3 AddClamped( Vector3& toAdd, float maxLength )

book_4_sparkGenerated
code_blocksInput

Description

The AddClamped method adds a given vector to the current vector and 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, you need to have an instance of a Vector3 object. You will pass a reference to the vector you want to add and a 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.0f