Camera jittering with Rigidbody

Hi! I’ll need to use a Rigidbory to my player in my game project, but when I try to move the player, my camera starts to jittering and the player dont’ fall. I’m using cinemachine.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float moveSpeed = 5.0f;
    public float rotationSpeed = 280.0f;

    float horizontal;
    float vertical;

    Rigidbody playerRigidbody;

    private void Awake()
    {
        playerRigidbody = GetComponent<Rigidbody>();
    }

    private void Update()
    {
        Vector3 moveDirection = Vector3.forward * vertical + Vector3.right * horizontal;
      

        Vector3 projectedCameraFoward = Vector3.ProjectOnPlane(Camera.main.transform.forward, Vector3.up);
        Quaternion rotationCamera = Quaternion.LookRotation(projectedCameraFoward, Vector3.up);
      

        moveDirection = rotationCamera * moveDirection;
        Quaternion rotationToMoveDirection = Quaternion.LookRotation(moveDirection);

        //transform.rotation = Quaternion.RotateTowards(transform.rotation, rotationCamera, rotationSpeed * Time.deltaTime);

        if(moveDirection.magnitude >= 0.1f)
        {
            transform.rotation = Quaternion.RotateTowards(transform.rotation, rotationToMoveDirection, rotationSpeed * Time.deltaTime);
        }
        //transform.rotation = Quaternion.RotateTowards(transform.rotation, rotationToMoveDirection, rotationSpeed * Time.deltaTime);



        //transform.position += moveDirection * moveSpeed * Time.deltaTime;

        playerRigidbody.velocity = moveDirection * moveSpeed;
    }

    public void OnMoveInput(float horizontal, float vertical)
    {
        this.vertical = vertical;
        this.horizontal = horizontal;
    }
}

If you are regarding a physics object (Rigidbody or Rigidbody2D), camera should always be done in FixedUpdate().

Here’s why:

Here is some timing diagram help:

You can try to change the update settings in cinemachine brain and also the interpolate setting on the rigid body.

I just had a jitter situation, although i believe it was different than hours, but i had to set the update and blend in cinemachine brain to smart update and fixed update. And i had to set rigid body interpolation to none.

All in the inspector.

I know that’s pretty vague but try adjusting those settings.

Also perhaps try a regular camera to see if its the same compared to cinemachine

Cinemachine does support FixedUpdate(), obviously:

https://docs.unity3d.com/Packages/com.unity.cinemachine@2.1/api/Cinemachine.CinemachineBrain.UpdateMethod.html