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 particularly useful for creating smooth transitions in animations or camera movements. The method uses a damping function to gradually change the current rotation towards the target rotation, taking into account the velocity of the change and the time elapsed.

Usage

To use the Rotation.SmoothDamp method, provide the current rotation, the target rotation, a reference to the velocity vector, the smooth time, and the delta time. The method will return the new rotation that is closer to the target, and it will update the velocity vector to reflect the change in rotation over time.

Parameters:

  • current: The current rotation from which to start the interpolation.
  • target: The target rotation to reach.
  • velocity: A reference to a Vector3 that represents the current velocity of the rotation change. This will be updated by the method.
  • smoothTime: A float representing the time it takes to reach the target rotation. A smaller value will result in a faster transition.
  • deltaTime: A float representing the time elapsed since the last frame. This is typically the frame time in seconds.

Example

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

Rotation newRotation = Rotation.SmoothDamp(currentRotation, ref targetRotation, ref velocity, smoothTime, deltaTime);

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