void SmoothMove( Transform& transform, float timeToArrive, float timeDelta )
void SmoothMove( Vector3& position, float timeToArrive, float timeDelta )

robot_2Generated
code_blocksInput

Description

The Rigidbody.SmoothMove method is used to smoothly transition a Rigidbody to a new position over a specified duration. This method is particularly useful for creating smooth animations or movements in a physics-based environment, ensuring that the transition appears natural and fluid.

Usage

To use the SmoothMove method, you need to provide the following parameters:

  • transform: A reference to a Transform object that represents the target position and orientation for the Rigidbody.
  • timeToArrive: A float value indicating the total time in seconds over which the movement should occur.
  • timeDelta: A float value representing the time step for the movement, typically the time elapsed since the last frame.

Ensure that the Rigidbody component is attached to a GameObject with a collider, as the Rigidbody requires a collider to function properly.

Example

// Example of using SmoothMove in a game update loop
public class MyGameComponent : Component
{
    private Rigidbody myRigidbody;
    private Transform targetTransform;
    private float timeToArrive = 2.0f; // Move over 2 seconds

    public override void Update()
    {
        float timeDelta = Time.Delta;
        myRigidbody.SmoothMove(ref targetTransform, timeToArrive, timeDelta);
    }
}