Description
The Clamp
method in the Rotation
struct is used to constrain the rotation to a specified maximum angular distance from another rotation. This method is useful when you want to limit the rotation change to a certain degree, ensuring smooth transitions or preventing excessive rotation.
Usage
To use the Clamp
method, you need to have an instance of the Rotation
struct. You can then call the method with the target rotation and the maximum allowed degrees of rotation.
Parameters:
to
(Rotation
): The target rotation to which you want to clamp the current rotation.
degrees
(System.Single
): The maximum number of degrees the rotation is allowed to change.
Returns: A new Rotation
instance that represents the clamped rotation.
Example
// Example of using the Clamp method
Rotation currentRotation = new Rotation();
Rotation targetRotation = Rotation.FromAxis(Vector3.Up, 90);
float maxDegrees = 45.0f;
// Clamp the current rotation to be within 45 degrees of the target rotation
Rotation clampedRotation = currentRotation.Clamp(targetRotation, maxDegrees);