Search Unity

Resolved Rigidbody movement with jitter

Discussion in 'General Graphics' started by wootrop, Nov 14, 2020.

  1. wootrop

    wootrop

    Joined:
    Mar 24, 2020
    Posts:
    15
    Hello!

    I'm experiencing a problem with rigidbody physics or camera following script.
    When I rotate the sphere around, everything is ok and there are no jitters; but the problem is when I try to move the sphere as you can see in the following gif.

    movement issue.gif

    I simply move the sphere in FixedUpdate with rbody.AddForce and ForceMode.VelocityChange.

    This is the CameraFollow.cs script that I'm using: https://pastebin.com/TYGhAPhb

    And these are the rigidbody settings:

    rbsettings.png
    As you can see I'm using interpolation on the rigidbody.

    What I'm doing wrong?
    I'm using Unity 2020.1.9f1.
    Thanks in advance...
     
  2. wootrop

    wootrop

    Joined:
    Mar 24, 2020
    Posts:
    15
    Thanks to the user dlich#9427 through the Unity Discord channel I simply solved by disabling interpolation on the rigidbody.

    He says that the important thing is to keep synced the camera position/rotation update cycle with the moving body update cycle. And he say this:

    " Updating during regular update, might provide smoother movement, but it's such a subtle difference that it's barely noticeable to human eye. It might get bigger if your framerate is high though, because the parity between fixed and regular updates becomes more apparent.
    So, I'd rather move your camera code into update and keep the interpolation on."

    So a better solution was moving the camera follow to the Update cycle, keep the physics on the FixedUpdate and enabling interpolation.

    In this manner I have a smooth movement in term of positions, but when I rotate the sphere the jittering occur again.

    So the final solution, thanks again to dlich#9427 was moving also the rotation logic (that was in the FixedUpdate loop) to the Update loop!

    Now everythings works like a charm! :D
     
    Last edited: Nov 17, 2020
  3. nightowl79a

    nightowl79a

    Joined:
    May 15, 2014
    Posts:
    10
    Amazing!!!! After hours of messing around and googling and re-writing my movement code and all kinds of other stuff... this finally fixed it. I always thought camera stuff should be in late update, but man this worked soooo good. Thanks!
     
  4. MichaelEGA

    MichaelEGA

    Joined:
    Oct 11, 2019
    Posts:
    40
    Thanks! Turning of interpolation did the trick. :)

     
  5. nmbileg

    nmbileg

    Joined:
    Sep 29, 2017
    Posts:
    22
    My man saved me a lot of freaking time!!! Thank you!
     
  6. nich2408

    nich2408

    Joined:
    Jun 27, 2018
    Posts:
    9
    So if a rigidbody is actively followed by a camera it's better to have interpolation on it.
    Thank you for the explanation!
     
  7. LuckyBeeYoutube

    LuckyBeeYoutube

    Joined:
    Jan 18, 2022
    Posts:
    1
    That is making my player super-fast. HELP! :(