Search Unity

Question Cinemachine jitter problem

Discussion in 'Cinemachine' started by TarasTech, Jul 25, 2021.

  1. TarasTech

    TarasTech

    Joined:
    Oct 20, 2017
    Posts:
    2
    Hello,

    So I've been using cinemachine freelook for my game I'm building. Its a 3rd person camera. Now I recently switched my movement from character controller to rigidbody, and that's when I started having jitter issues. Now I understand that rigidbody uses fixed update for updating the player movement. I've tried going though many of the different cine machine options and changing it between smart, fixed, and late update. I managed to get a almost perfect version, but there's still small amounts of jitter when moving side to side. When I move straight forward or backwards, I have no issue. And the camera panning around during movement causes no issue as well. But when I start moving sideways, while facing forward, I get little jitter problem that is visible, and is annoying. This might be normal, and I'm just obsessing's over nothing, so I'm looking for some help from anybody. Heres my current best cinemachine settings:





    Here's my player movement script:
    Code (CSharp):
    1.  
    2. void Update()
    3.     {
    4.         if (view.IsMine)
    5.         {
    6.  
    7.             if (Input.GetMouseButtonDown(0))
    8.             {
    9.                 ac.animator.SetTrigger("Attack");
    10.             }
    11.  
    12.             isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
    13.  
    14.             _inputs = Vector3.zero;
    15.             _inputs.x = Input.GetAxis("Horizontal");
    16.             _inputs.z = Input.GetAxis("Vertical");
    17.             _inputs.Normalize();
    18.            
    19.  
    20.             if (Input.GetButtonDown("Jump") && isGrounded)
    21.             {
    22.                 rb.AddForce(Vector3.up * Mathf.Sqrt(jumpHeight * -2f * Physics.gravity.y), ForceMode.VelocityChange);
    23.             }
    24.         }
    25.     }
    26.  
    27.     void FixedUpdate()
    28.     {
    29.         if (view.IsMine)
    30.         {
    31.             if (_inputs.magnitude >= 0.1f)
    32.             {
    33.                 float targetAngle = Mathf.Atan2(_inputs.x, _inputs.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
    34.                 float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothTime);
    35.                 transform.rotation = Quaternion.Euler(0f, angle, 0f);
    36.                 _inputs = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
    37.                 _inputs.Normalize();
    38.             }
    39.             rb.MovePosition(rb.position + _inputs * speed * Time.deltaTime);
    40.         }
    41.     }
    Any help appreciated! I can post a video, but its hard to see the jitter if the video isnt 120 fps
     
  2. TarasTech

    TarasTech

    Joined:
    Oct 20, 2017
    Posts:
    2
    So quick update, I realized dampening was causing the world jitter. I turned it down all the way, and the world jitter stopped, though I'm finding that the camera still seems laggy on my 144hz monitor. It had like light stutters, and I cant figure out why. Any ways I could fix that?
     
  3. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,728
    If you get jitter that is visible with damping it points to an uneven animation of the player. You can hide it by turning down the damping, but the problem is still there. Do you have some script somewhere that's modifying the Player's transfom outside of FixedUpdate? I ask because you have the Brain on Smart Update, and your vcam is showing that it's being updated in LateUpdate:

    upload_2021-8-2_9-34-10.png

    That's a sign that the target's transfom is being modified outside of FixedUpdate (SmartUpdate tracks this and will choose LateUpdate unless the target's transform is being modified exclusively in FixedUpdate). If you modify the transform in both Fixed and Late Update, it's almost impossible to get smooth motion. You should fix this.