Search Unity

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:
    715
    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:
    715
    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);