Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Resolved FreeLook Camera jitter slightly when my character moving and rotating view.

Discussion in 'Cinemachine' started by Beike, Aug 13, 2022.

  1. Beike

    Beike

    Joined:
    Dec 10, 2017
    Posts:
    13
    Unity Version: 2020.3.30f1c1
    Cinemachine Version: 2.6.15
    Brain UpdateMethod: Fixed Update

    My game(it is a 3rd game) download link:https://drive.google.com/file/d/1yfoEyi9uTb55j-4a4E8cjXzQ-3_OGkbg/view?usp=sharing

    My character moves by setting rigidbody velocity.
    Only rotating view or only move character,jitter does not take place.
    But when move and rotate at the same time,jitter takes place.
    May be it is so slight to detect.But I can feel something wrong.
    You can download my game, move around the cube wall and rotate view to focus on the wall.
    The jitter at this time is relatively large.You can also rotate view up and down to accentuate jitter.
    The jitter causes my game seem to drop frames,but I can play my game over 60FPS.How can I solve it?:(
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,022
  3. Beike

    Beike

    Joined:
    Dec 10, 2017
    Posts:
    13
    Thanks for your reply:D.I've already tried
    Late Update and Smart Update are not obviously suitable for rigidbody,because they cause moving jitter.
    As for Manual Update,I call update function in my player's FixedUpdate.It's the same cause moving jitter.:(
     
  4. Beike

    Beike

    Joined:
    Dec 10, 2017
    Posts:
    13
    I downgrade cinemachine version to 2.6.11 and the jitter disappears.So strange!Why does the higher version have bug that the old version does not?
     
  5. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Could you submit a bug report with your project or a simplified version where we can reproduce the bug? It is difficult to tell what is causing the issue.
     
    Gregoryl likes this.
  6. Beike

    Beike

    Joined:
    Dec 10, 2017
    Posts:
    13
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,268
    Thanks for the upload. The problem is that you are rotating your rigidBody improperly in Update(), which means that it moves on FixedUpdate but rotates on Update(). These two clock are not synchronized, so you will get jitter as a result of aliasing between the different clocks.

    Such inconsistencies are a common error when using RigidBodies. It is important to ensure that 100% of the rigidBody motion happens in a way that is compatible with the physics simulation. So, instead of directly touching the rigidBody's transfrorm, you must go through the rigidBody using rb.MoveRotation() and rb.MovePosition(), and you must do it in FixedUpdate().

    When I modify your Player script as follows, the jitter disappears. I did not change the Cinemachine version.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Player : MonoBehaviour
    6. {
    7.     [SerializeField]
    8.     Rigidbody rigidBody;
    9.     public Vector3 moveDirection;//Player's move direction.Vector3.Zero is no move.
    10.     [SerializeField]
    11.     float moveSpeed = 5;//Player's moving speed
    12.  
    13.     private void FixedUpdate()
    14.     {
    15.         UpdateRotation();
    16.         UpdateVelocity();
    17.     }
    18.     void UpdateRotation()
    19.     {
    20.         if (moveDirection != Vector3.zero)//Only update player's rotaion when moving
    21.             rigidBody.MoveRotation(Quaternion.Slerp(rigidBody.rotation, Quaternion.LookRotation(moveDirection, Vector3.up), Time.deltaTime * 7.5f));
    22.     }
    23.     void UpdateVelocity()
    24.     {
    25.         Vector3 newVel = Vector3.Lerp(rigidBody.velocity,moveDirection * moveSpeed,Time.fixedDeltaTime * 5f);
    26.         rigidBody.velocity = newVel;
    27.     }
    28. }
    29.  
     
  8. Beike

    Beike

    Joined:
    Dec 10, 2017
    Posts:
    13
    It is sad that the jitter does not disappear after I modify my script as you said.Maybe you didn't find out the jitter I said.Please look at the compare video.
    https://drive.google.com/file/d/1UP588ZeMndY6arYWRy1NoM4fNpSQS5XW/view?usp=sharing
    It is obvious that version 2.6.15 has some jitter.If it is hard to find solution,I will select Cinemachine 2.6.11.
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,268
    I looked at the video, and it looks to me to be render frame vs physics frame aliasing.

    Have you tried enabling RigidBody interpolation on the player? Without it, it's difficult to get things to be perfectly smooth, because of render time and physics timestep aliasing.
     
  10. Beike

    Beike

    Joined:
    Dec 10, 2017
    Posts:
    13
    Ohhhhhhh! I didn't know about it until now. I enable it and it causes my player jitter rather than environment.But I switch UpdateMethod to SmartUpdate,and finally get a satisfactory result.I don't know why SmartUpdate can fit for rigidbody's moving,but everything goes well.Thank you very much for your help!!!!!;););)
     
    Gregoryl likes this.
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,268
    Interpolation tells the physics engine to interpolate the player transform at render time, effectively converting FixedUpdate() motion to Update() motion.

    SmartUpdate on the CM Brain auto-detects how the target is moving (FixedUpdate or Update) and causes any camera with that target to update the same way.

    If you set the Brain's update method to LateUpdate, it will also work.
     
  12. Beike

    Beike

    Joined:
    Dec 10, 2017
    Posts:
    13
    Oh,I see.Thank you again!