Description
The Clamp
method in the Rotation
struct is used to constrain the rotation to a specified maximum angular distance from a target rotation. This method is useful when you want to limit how much a rotation can change in a single step, ensuring smooth transitions and preventing abrupt changes.
Usage
To use the Clamp
method, you need to have an instance of a Rotation
object. You can then call the method on this instance, passing in the target rotation and the maximum allowed change in degrees.
Parameters:
to
(Rotation): The target rotation you want to clamp towards.
degrees
(System.Single): The maximum angular distance in degrees that the rotation can change towards the target.
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 towards the target rotation
Rotation clampedRotation = currentRotation.Clamp(targetRotation, maxDegrees);
// The clampedRotation will be at most 45 degrees away from the currentRotation towards the targetRotation.