static Rotation SmoothDamp( Rotation current, Rotation& target, Vector3& velocity, float smoothTime, float deltaTime )

book_4_sparkGenerated
code_blocksInput

Description

The Rotation.SmoothDamp method is a static function that smoothly interpolates between two rotations over time. It is useful for creating smooth transitions between orientations, such as when rotating an object to face a target direction. The method uses a damping function to gradually reduce the difference between the current and target rotations, resulting in a smooth motion.

Usage

To use the Rotation.SmoothDamp method, provide the current rotation, the target rotation, a reference to a velocity vector, the desired smooth time, and the delta time for the current frame. The method will return the new interpolated rotation.

The velocity parameter is used internally to track the rate of change of the rotation, and should be initialized to zero before the first call. The smoothTime parameter determines how quickly the rotation reaches the target; smaller values result in faster transitions. The deltaTime parameter should be the time elapsed since the last frame, typically provided by the game engine.

Example

// Example usage of Rotation.SmoothDamp
Rotation currentRotation = Rotation.Identity;
Rotation targetRotation = Rotation.FromAxis(Vector3.Up, 90.0f);
Vector3 velocity = Vector3.Zero;
float smoothTime = 0.3f;
float deltaTime = Time.Delta;

// Smoothly interpolate the rotation
Rotation newRotation = Rotation.SmoothDamp(currentRotation, ref targetRotation, ref velocity, smoothTime, deltaTime);

// Apply the new rotation to an object
myGameObject.Rotation = newRotation;