Cinemachine + Pixel Perfect Camera Jittering (2D)

Hey everyone, I’m attempting to use Cinemachine to track my player, but whenever the camera pans to track the player’s movements the player object jitters around. I’m using a rigidbody2D and velocity to move my player around; I’ve seen jittering issues attributed to calling movement for a rigidbody in Update() instead of FixedUpdate(), but I’m calling all player movement functions inside of FixedUpdate(). (Video link)



image

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Yarn.Unity;

public class PlayerController : MonoBehaviour
{
    // Our dialogue system parameters
    public bool _canInteract = false;
    public bool _canMove = true;

    // Our parameters for where to start each scene in coordinates (assigned via LoadNewScene script)
    public Vector2 _newScenePosition;


    // Our speed & speed limit values
    float _moveSpeed = 5f;
    float _speedLimiter = 0.8f;

    // Our empty floats for our movement vector
    float moveX;
    float moveY;
    Vector2 _moveDirection;

    [SerializeField] Rigidbody2D _rb;
    [SerializeField] CircleCollider2D _c2D;



    void Update() // Calling our ProcessInputs function
    {
        if (_canMove)
        {
            InteractionOffset();
        }

    }

    void FixedUpdate()
    {
        // Physics calculations

        if (_canMove)
        {
            ProcessInputs();
        }

        Move();
    }


    void ProcessInputs() // Checking to see which direction the player wants to move
    {
        moveX = Input.GetAxisRaw("Horizontal");
        moveY = Input.GetAxisRaw("Vertical");

        _moveDirection = new Vector2(moveX, moveY);
    }


    void Move()  // Moving our player based on ProcessInputs()
    {

        if (moveX != 0 && moveY != 0) // If moving diagonally, we slow down the player with our speed limiter
        {
            _rb.velocity = new Vector2(_moveDirection.x * _moveSpeed * _speedLimiter, _moveDirection.y * _moveSpeed * _speedLimiter);
        }


        else if (moveX != 0 || moveY != 0) // If moving horizontally or vertically, we don't use the speed limiter
        {
            _rb.velocity = new Vector2(_moveDirection.x * _moveSpeed, _moveDirection.y * _moveSpeed);
        }

        else // If not moving, we stay still!

        {
            _rb.velocity = new Vector2(0, 0);
        }

    }


    // Checking if our player is in an interactable area

    public void OnTriggerEnter2D(Collider2D col)
    {
        _canInteract = true;
    }

    public void OnTriggerExit2D(Collider2D col)
    {
        _canInteract = false;
    }

    void InteractionOffset()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            _c2D.offset = new Vector2(-1.05f, 0.0f);
        }

        else if (Input.GetKeyDown(KeyCode.D))
        {
            _c2D.offset = new Vector2(1.05f, 0.0f);
        }

        else if (Input.GetKeyDown(KeyCode.S))
        {
            _c2D.offset = new Vector2(0.0f, -1.05f);
        }

        else if (Input.GetKeyDown(KeyCode.W))
        {
            _c2D.offset = new Vector2(0.0f, 1.05f);
        }

    }

}

`

Looks like you haven’t set up Cinemachine correctly. The CM Brain should only be on the main camera.

Also: can you show the inspector for the player? I want to see the settings on the Rigidbody2D.

Removed the CM Brain from the vcam, thanks for that - here’s the rigidbody settings on the player

Update - I disabled Cinemachine and made the main camera a child of the player, and the jittering was still present, so the issue isn’t with Cinemachine. Still not sure how to solve it

Further update - I realized the jittering is occuring when the camera component is coming into contact with the polygon collider of the bounding shape in the confiner. No clue as to why this is the case as the polygon collider is set to be a trigger.

Video

Final update - turns out, it was because the polygon collider i used had some crooked lines. i hope this saves someone in the future a headache

I notice that you have the RB set to interpolate, while the Brain is updating in FixedUpdate. Change it to LateUpdate or SmartUpdate.