Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Camera Stutter/Jitter (using Interpolation)

Discussion in 'Editor & General Support' started by woolleybboy, Apr 12, 2021.

  1. woolleybboy

    woolleybboy

    Joined:
    Mar 19, 2021
    Posts:
    5
    We are making a simple game where you are a cube and you go down a hall and dodge stuff. Our issue is with the camera following the player. When the cube moves side to side it stutters/jitters. I have interpolate turned on on the cubes rigidbody but it doesnt make a difference. The cube is being move with AddForce in fixedupdate, the inputs are handled in update, and the camera movement is done in LateUpdate. So far this is the best order ive found but the issue is still very noticeable. I have tried using the Lerp method and the smoothDamp method but neither have worked. using the formula 1 - Mathf.Exp(-50 *Time.deltaTime (to keep the lerp range between 0-1)) worked slightly but its far from completely fixed. Is there a way to completely remove the camera jitter? And is there also a way to update the camera position smoothly while keeping it independent of the deltatime frame dependency? (also the cube is moving at a pretty quick speed, and the jitter is worse the faster the camera tries to keep up).
     

    Attached Files:

  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I would temporarily remove the smoothdamp and lerp code, and just directly set the camera relative to the player in LateUpdate. If you still see jitter, then it should be from the player jittering, not the camera. I'd test this in a build, not the Editor, because Editor overhead can produce its own jitter. If you find there is jitter with the player itself, there's not much you can do with the camera script to get rid of it. You'd need to focus on the player movement jitter first.

    I'd also check the profiler, again of a build, to verify you aren't getting uneven frame times, which can result in the appearance of jitter even if you have well designed movement and camera follow code. Lastly verify you aren't far from origin. If you're 1k or more from origin (depending on the scale of what you're doing really), you may need to implement a floating origin system. Otherwise floating point math precision issues may be making jitter free movement impossible.

    Once you have all that done, then I'd come back to the camera follow script. Good luck.
     
  3. woolleybboy

    woolleybboy

    Joined:
    Mar 19, 2021
    Posts:
    5

    turns out everything was fine but the scale of the player was tiny
     
  4. woolleybboy

    woolleybboy

    Joined:
    Mar 19, 2021
    Posts:
    5
    Bringing the scale of the player to around 1, 1, 1 immediately solved the jitter