Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. Dismiss Notice

Question Local rotation smoothing/interpolation of a rigidbody?

Discussion in 'Physics' started by CloudyVR, May 23, 2023.

  1. CloudyVR

    CloudyVR

    Joined:
    Mar 26, 2017
    Posts:
    709
    For example if I have a bicycle that can lean on Y axis without constraints, but interpolates along X so to avoid doing constant wheelies, but still the bike will follow the contours of hills, how to achieve this with a rigid body?

    Unity's rigid body only has a checkbox to disable the rotation axis entirely but is not very helpful since the bike would always be level.

    Instead of locking the local X rotation, how could I interpolate the local X rotation of a rigid body?
     
  2. CloudyVR

    CloudyVR

    Joined:
    Mar 26, 2017
    Posts:
    709
    I think the solution was to limit the angularVelocity of the rigid body in local space:
    Code (CSharp):
    1. var angularVelocityLocal = transform.InverseTransformDirection(rb.angularVelocity);
    2. angularVelocityLocal.x = angularVelocityLocal.x * 0.1f;
    3. rb.angularVelocity = transform.TransformDirection(angularVelocityLocal);