Cinemachine camera lagging behind player and randomly moving around.

I have been having a problem with Cinemachine where my freelook camera will be further behind the player while the player is moving away from it, which I do not want. Also, the camera sometimes randomly flashes another perspective for about a frame, which is very jarring. Is there any way I can fix this? I have been searching online and haven’t found anything that relates to my problem. My cinemachine brain is set to late update so that isn’t the problem.

here is my cinemachine camera’s settings (the rig settings aren’t accurate because I have a custom script to change them)



8852398--1207213--upload_2023-3-4_12-30-18.png
(sorry for windows 10 watermark)

here is my script for changing camera zoom:

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

public class CameraZoom : MonoBehaviour
{

    public Cinemachine.CinemachineFreeLook cam;
    private float zoom = 5;
    private float sensitivity = 1;

    // Update is called once per frame
    void Update()
    {
        zoom += Input.mouseScrollDelta.y * sensitivity;

        zoom = Mathf.Clamp(zoom, 3, 30);

        cam.m_Orbits[1].m_Radius = zoom;
        cam.m_Orbits[0].m_Height = zoom;
        cam.m_Orbits[2].m_Height = -zoom;

    }
}

here is my code for player movement:

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

public class ThirdPersonMovement : MonoBehaviour
{
    public CharacterController controller;
    public Transform cam;
    public Transform character;

    public float speed = 6f;

    Vector3 moveVector;
    bool isJumping = false;
    float timeSinceJump = 0f;
    Vector3 jumpVector;


    // Update is called once per frame
    void Update()
    {

        bool isGrounded = Physics.Raycast(character.position, Vector3.down, 1.1f);

        moveVector = Vector3.zero;                                              // prevent building speed every frame

        transform.rotation = Quaternion.Euler(0, cam.eulerAngles.y, 0);         // make the player always face away from the camera

        Vector3 forward = (transform.rotation * Vector3.forward).normalized;    // determine which direction is forward
        Vector3 camDir = (cam.rotation * Vector3.forward).normalized;           // determine which direction the camera is facing

        Vector3 right = Vector3.Cross(forward,camDir).normalized;               // find vector perpendicular to camDir and forward to find which way is right

        // make player move in the correct direction
        if (Input.GetKey(KeyCode.W))
        {
            moveVector += forward;
        }
        if (Input.GetKey(KeyCode.S))
        {
            moveVector += forward * -1f;
        }
        if (Input.GetKey(KeyCode.D))
        {
            moveVector += right;
        }
        if (Input.GetKey(KeyCode.A))
        {
            moveVector += right * -1f;
        }
        if (Input.GetKey(KeyCode.Space) && isGrounded)
        {
            isJumping = true;
        }

        if (timeSinceJump >= 0.5)
        {
            isJumping = false;
            timeSinceJump = 0f;
        }
        if (isJumping)
        {
            jumpVector = Vector3.up * 10 - Vector3.up * timeSinceJump * 10 * 2;
            timeSinceJump += Time.deltaTime;
        } else
        {
            jumpVector = Vector3.zero;
        }

        if (!isGrounded && !isJumping)
        {
            controller.Move(Physics.gravity * Time.deltaTime);
        }

        controller.Move(moveVector.normalized * speed * Time.deltaTime + jumpVector * Time.deltaTime);        // move player



       
    }
}

I don’t know where the problem might be so I just put everywhere that I thought could be the problem.


Sorry for the slow response. Do your want your camera to be at a fixed distance from the player, regardless of how fast the player is moving? If so, set the Z damping to 0 in the Orbital Transposer (open up the “Body” section of the FreeLook to find the orbital transposer damping settings). Do it for all 3 rigs.