Search Unity

Resolved Rigidbody interpolatioin causing strange rotation effect.on other ojbject

Discussion in 'Physics' started by kriskoon, Jun 1, 2021.

  1. kriskoon

    kriskoon

    Joined:
    Aug 24, 2020
    Posts:
    5
    I am working on a Unity project in which I have a sphere and another custom mesh. The sphere is under control of the physics engine and is allowed to roll across the other mesh. That other mesh is able to be manipulated by the player. I also have a chase camera following the sphere as it rolls. To make the motion smoother, I have enabled interpolation on the sphere's rigidbody. Doing this, however, causes the other mesh (that is controlled by the player) to appear jerky when rotated.

    To quickly examine this issue further, I recorded a video at 240 fps slow motion with my phone's camera pointed at my monitor while in play mode in the Unity editor. Watching this video revealed that, when the mesh was rotated along its axis in one direction, it would tend to rotate backward in the wrong direction, slightly, during some frames. Overall, it would progress in the correct direction at the right speed, but the motion would seem jerky when viewing at full speed due to it appearing to move backward slightly on some frames. It is not just the editor. It also occurs in an Android build that I tried.

    Some more information: the mesh under the player's control has a mesh collider and no rigidbody. It is rotated in script by "transform.RotateAround()" during "FixedUpdate()" to move it clockwise or counter-clockwise by 0.75 degrees around its axis every timestep. The jerky motion doesn't occur if the sphere's rigidbody interpolation is set to "None", but occurs when it is set to either "Interpolate" or "Extrapolate". The sphere's rigidbody collision detection setting did not seem to make a difference.

    This is with Unity version 2021.1.9. Any thoughts on this issue? I assume that this is a problem of the frames with interpolated motion using wrong data about the rotated mesh. I can provide the video I recorded if it would be of help.

    Thanks!
     
    Last edited: Jun 1, 2021
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    The issue seems to do with having two objects using different interpolation / motion methods. Camera is following an object with interpolation (sphere) while other object is moving without interpolation (custom mesh). Therefore, the custom mesh appears jerky.

    I'd keep the interpolation enabled in the sphere and enforce some kind of interpolation in the custom mesh. This could be achieved with one of these methods:
    • Rotate the custom mesh from Update instead of FixedUpdate. Specify a rotation rate per second (instead of per timestep) and multiply it by Time.deltaTime to get the actual rotation value every step.
    • Add a Rigidbody to the custom mesh, make it kinematic and enable interpolation. Then move it with Rigidbody.MovePosition and Rigidbody.MoveRotation from FixedUpdate.
     
  3. kriskoon

    kriskoon

    Joined:
    Aug 24, 2020
    Posts:
    5
    Here is the video I recorded. The effect is noticeable at 1:00 and 1:37. You may have to fullscreen it to see it clearly. It looks to me as if the mesh is wavering back and forth. Is this really because it's not interpolated as the sphere is?

     
  4. kriskoon

    kriskoon

    Joined:
    Aug 24, 2020
    Posts:
    5
    I finally fixed this by setting up a rigidbody on the parent of the mesh. It's now rotating smoothly.
     
    Edy likes this.
  5. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,510
    Yes, the video looked like an interpolation issue to me. Additionally, using a rigidbody is almost mandatory for the collisions to be processed correctly. Anyways, glad to know you've sorted it out!