Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Cinemachine attached to animated bone with damping creates jitter

Discussion in 'Cinemachine' started by mrwillt1986, Jan 6, 2023.

  1. mrwillt1986

    mrwillt1986

    Joined:
    Mar 26, 2021
    Posts:
    8
    Hey all, so I'm building a 1st person camera that attaches to the head bone of the character. I'm aware it would be easier not to attach it to the bone, but I'm trying to make the camera part of the 3rd person model.

    Using IK its easy enough to fix the eye stabilization issue, but I want to dampen the head motion using Cinemachine. If you have zero damping you get a fair amount of head bob and when you take that into a real level with real terrain this can create to much movement.

    I was hoping to use cinemachine damping with a bounding box but it appears that as soon as you add any damping to the model it highlights incredible jitter on the animation.

    I've tried updating the camera manually but nothing seems to work.

    There is the option of using IK on the head of the character model and stabilizing the head, but that has its disadvantages when it comes to the motion of the animation.

    Any ideas?

    Video here:

     
  2. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    It is possible that the animation has jitter that is more pronounced when the camera is looking at it from a different angle.
    If you disable the virtual camera, and attach the Unity Camera directly to the same spot and change the rotation of the camera a little bit, do you see jitter?

    If you don't see jitter without Cinemachine:
    Have you tried the other update modes on CinemachineBrain (Late, Fixed)? When you tried manual update, what did you do?

    In your recording the player seems to be drifting a bit forward. How is this achieved? Is it part of the animation?
    Is the player a rigidbody? If so, is it interpolated or not (Rigidbody component has a setting for interpolation)?
     
  3. mrwillt1986

    mrwillt1986

    Joined:
    Mar 26, 2021
    Posts:
    8
    I appreciate the quick reply.

    The drift is me coding a very small movement forward on the character controller so I don't have to press anything as I played with settings.

    The jitter is only shown when using dampening on cinemachine. If you disable any form of dampening, this issue goes away. Which I guess is obvious, as any jitter that was there gets hidden without a dampener. I want a dampener because it would help reduce head bob. Without dampening the Y Axis gets all the motion of the player as they run.

    If you just use a normal camera, you get a good result, but again thats because the normal camera has no dampening.

    I tried late/fixed, but ultimately I was handling the update in script because I have IK applied to the model so I need to update the camera after IK has finished.

    For reference, this was an insanely stripped down version which didn't have any components like IK that could interfere.

    I'm using a character controller and it appears that by updating the CC in Update, you'll always get some amount of jitter in Cinemachine if you use dampening. Changing to a rigidbody does fix this issue. But also updating the CC in fixedupdate seems to fix this issue as well.

    I confirmed this theory by taking a object, attaching a cube as a child, then attaching a virtual camera as a child of the main object and moving the CC forward by a tiny amount each frame. In update, slight jitter, in fixed, all good.

    I was then insanely hopeful and got excited, but as soon as I enabled the animator, we are back to having jitter. So I've fixed half of the jitter, but it appears cinemachine doesn't do well with dampening an animation.

    I've come up with a workaround to effectively take control of the Y Axis in a lerp... it isn't what I wanted as cinemachine's bounding collider etc is quite a handy effect to use, but at this moment in time I can't work out why or how to stop this jitter on the animation.

    For reference I've also tried changing animations. I'm using mocaponline animations, I've also tried simple mixamo animations in both 30/60fps variants.
     
  4. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    It sounds like that things are updated in different updates: FixedUpdate, Update. The problem is that these two updates are not synced. If you attach the camera to something that's updated in fixed update, then you'll see jitter on the things that are updated in Update(), and vice versa.

    To fix it, turn on interpolation on your RigidBodies.
    Rigidbody-interpolate.png

    Have a look at this forum thread as this discusses this issue in depth:
    https://forum.unity.com/threads/cinemachine-crazy-jitter.465865/

    Script execution order may be useful:
    https://docs.unity3d.com/2022.2/Documentation/Manual/class-MonoManager.html
     
  5. mrwillt1986

    mrwillt1986

    Joined:
    Mar 26, 2021
    Posts:
    8
    I've tried a combination of pretty much everything I can think of but whatever happens I get some form of jitter. I've tried moving my entire code base into update, fixed update, late update and every combination of each script between and I either end up with jitter with no dampening, or jitter with dampening.

    I am using FinalIK for handling IK which has to run in LateUpdate as it needs to manipulate animation.

    I do think FinalIK is making this considerably harder to achieve... though I'm really not sure whats going on now.
     
  6. mrwillt1986

    mrwillt1986

    Joined:
    Mar 26, 2021
    Posts:
    8
    Well.... I'll admit fault. So I had a time.fixedDeltaTime in character controller movement. That 1 thing completely screwed things.

    I hang my head in shame!

    Let it be a lesson to triple check a simple typo.
     
    gaborkb likes this.
  7. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    It's a simple thing to miss! I am happy it is working correctly now :)