Jitter on moving objects when Cinemachine camera moves (2D)

Hi everyone!

In my 2D platformer, my Cinemachine camera follows the player perfectly smoothly. However, I’m getting bad jitter on the other moving objects in the scene.

When the player (and camera) moves, these other moving objects stutter, especially if they are moving in a different direction. But if the player/camera stands still, those exact same objects move perfectly smoothly.

What I’ve already tried (without success):

  • Changing the Cinemachine Brain Update Method (Smart, Late…).
  • Enabling Interpolate on the Rigidbody2D of the moving objects.

Does anyone know what might be causing this desync? Any help is appreciated! Thanks.

What is your target platform? Is it related to the build or the editor, or both?

Take a look at the VSync Count option that helps to avoid Screen Tearing in the build.

For Editor’s Play Mode, there is a VSync option in Game View.

If your on macOS then this is your issue: Stuttering in 2023.2 and 6000.0 in a minimal URP project on macOS

Perhaps this is an issue of perception?

When the player moves and the camera tracks the player, the other objects won’t suddenly change their motion from smooth to non-smooth unless:

  • you change how you move them
  • they are parented to something that moves along with the player/camera and you may be trying to compensate for that “parental motion”

If the jitter is a perception issue it could be caused by pixel perfect positioning with pixel snapping - given a low enough resolution, this would force motion to snap to multiples of pixels for instance at 1920x1080 resolution a pixel resolution of 192x108 with pixel snapping would mean objects’ minimum move distance would be 10 pixels at a time - this can seem like jitter.

Note that Interpolation on Rigidbody doesn’t automatically mean it will work, at least if 2D physics has the same issues as 3D physics where interpolation will only work correctly if you either call MovePosition/MoveRotation (kinematic) or use AddForce/AddTorque (dynamic) and you do so from FixedUpdate, not Update.

To that end, please post the code you use to move those objects.

Hi! The issue occurs both in the editor and in the compiled version, whether for Windows or Android.
I’ve tried the different VSync options, but it doesn’t seem to improve. :frowning:

Thanks for the reply!
I’ve created an extremely basic scene to show my problem in a video. As you can see, the red cube shows a jitter effect, especially when the player (green object) is moving.

However, the green cube looks smooth…

This is the script I use for the cube’s movement:

using UnityEngine;

[RequireComponent(typeof(Rigidbody2D))]
public class LateralMovement : MonoBehaviour
{
    [Header("Movement Settings")]
    public float speed = 3f;
    public float movementDistance = 5f;

    private Rigidbody2D rb;
    private float initialPositionX;
    private int direction = 1;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        initialPositionX = transform.position.x;
    }

    void FixedUpdate()
    {
        float currentDistance = transform.position.x - initialPositionX;

        if (direction == 1 && currentDistance >= movementDistance)
        {
            direction = -1;
        }
        else if (direction == -1 && currentDistance <= -movementDistance)
        {
            direction = 1;
        }

        rb.linearVelocity = new Vector2(direction * speed, rb.linearVelocity.y);
    }
}

That’s an excellent test and a very clear video.

To me it looks like FixedUpdate vs Update aliasing. Can you show the script for moving the green object? Also, we need to know whether interpolation is enabled for the red cube.

Best practice is to add Interpolation to the red Cube’s Rigidbody, and to put the CM Brain in LateUpdate mode. If the green object also has a Rigidbody, make sure to follow the rules for correctly moving Rigidbodies, and to have interpolation enabled on that as well. If it’s not using a Rigidbody, then normal Updating while taking deltaTime into account is the way to go.

With that, everything should move smoothly.