Search Unity

Question Camera Follow jitter while using transform.position = anotherPosition

Discussion in 'Cinemachine' started by EricChan, Jan 11, 2023.

  1. EricChan

    EricChan

    Joined:
    Jul 14, 2014
    Posts:
    8
    Hi, I have a simple object that moved along X axis and I want my camera following it.

    upload_2023-1-11_15-37-35.png

    I am using this setup to follow the cube. The cube is moved by the follow script in Update()
    Code (CSharp):
    1. var position = transform.position;
    2. position.x += 0.03f;
    3. transform.position = position;
    No matter I use which update in the brain, it still jitters.
    The only way to fix this is to set the damping to 0, or use FixedUpdate for both the movement script and the brain update.

    May I know what is causing this issue? Many thanks.

     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,059
    1. setting in both Update and LateUpdate might help
    2. Use things like smoothdamp and/or lerp to smooth out camera movement. Almost all games smooth camera movement
     
  3. EricChan

    EricChan

    Joined:
    Jul 14, 2014
    Posts:
    8
    Thanks for the quick reply!

    It is already using LateUpdate in the Cinemachine brain.
    upload_2023-1-11_16-3-42.png
    And actually it is the damping of the vcam causing the jitter in my case.

    Do you have any advise on this matter? Thanks in advance.
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,059
    Why dont you use the cinemachine for following the object?

    EDIT: nvm, I thought that code was for the camera. Did you follow a guide for the cinemachine?
     
  5. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    The movement script is wrong. It will have different result based on fps, and that's why you may see jitter, because the movement itself is jittery.

    You could multiply by Time.deltaTime to smooth the movement.
    Code (CSharp):
    1.  
    2. public class Move : MonoBehaviour
    3. {
    4.     public float Speed = 3;
    5.  
    6.     void Update()
    7.     {
    8.         var position = transform.position;
    9.         position.x += Speed * Time.deltaTime;
    10.         transform.position = position;
    11.     }
    12. }
    13.  
    Have a look at this thread that may provide more information on the subject: https://forum.unity.com/threads/c-how-to-use-time-deltatime-to-move-object-smoothly.307197/

    The jitter is most probably not related to Cinemachine. If you'd attach your Camera (with CinemachineBrain disabled) to the Cube, you'd see jitter. If that is not the case, let me know ;)

    Note
    If you have damping, then you may see a pop, in that case call OnTargetObjectWarped on your Virtual Cameras whose target got moved.
    See this thread: https://forum.unity.com/threads/rep...how-to-avoid-the-popping.514293/#post-3396611
     
    Last edited: Jan 11, 2023
    Gregoryl likes this.