Search Unity

How to correctly manipulate bone rotations? (without jittering)

Discussion in 'Animation' started by John_Leorid, Jun 19, 2019.

  1. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    As you may already know, if you have any object updated in the same update method as the camera, it will jitter on the screen - see this post for reference:
    https://answers.unity.com/questions/935169/updatelate-update-jitter-problemnon-fixedupdate-re.html

    And here comes the problem: changing bone transforms can only be done in LateUpdate(), changing the camera transform too, because I move the character during Update() and fixed update will also cause jittering.
    So I change the character bones (for aiming) in the LateUpdate() and move the camera in LateUpdate() which causes jittering.

    I tested a few things, stripped out any other possible cause of the jittering and tried to run both scripts (CameraMove, BoneMove) in all available Update Functions without any solution so it won't jitter.
    In the editor view as well as viewed by a fixed camera, there is no jittering. The legs, which are not affected by the BoneMove script are not jittering - just the ones I manipulate in LateUpdate().

    So how to solve this problem? Would be nice if the unity team could answer here, because I think I am not the only one with this issue.
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    Calculate where you want things to be when you move the camera, then just keep applying the most recently calculated value in LateUpdate.
     
  3. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    It's not a Performance issue, the jittering happens, because bones are moved in the same Update as the camera. If I don't move the camera, the affected bones move smoothly (as well as everything else).
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    I didn't say anything about performance. Jittering should not happen if you move everything in the same update loop. What does your code actually look like?
     
  5. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    Here is the example project: https://github.com/leorid/LateUpdateJitter

    you can clearly see the jittering, now imagine "Cube" to be a spine bone of an animated third person character and imagine "Cube (1)" to be the weapon of said character.
    Also you can assume that I will have some movement, on the character in the Update() function, so I can't just put the camera code there - I need the cam in LateUpdate() when all movement is done.
     
  6. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,570
    It looks fine to me. The only time I get jitter is when it starts or stops pointing at the other cube in the scene (a slight jump because the raycast hits a very different position to the previous frame) and when the "Cube (1)" is actually in the middle of the screen so the raycast hits it and rotates it out of the way then hits the ground and puts it back in the middle of the screen again.

    Recording.gif

    Perhaps you could record a video of the problem? If you don't have a program for it, Screen2Gif is pretty good.
     
  7. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    I just wanted to make a video and suddenly, it was smooth .. well, I opend up my main project and the issue is still present. Maybe this has to do with the script execution order of late update?
    IDK but if others face the same problem as I do: it'd be nice if you'd leave a comment here.
     
  8. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    Well heres how the exact same script & setup (same camera&aimCorrection script, same parenting and everything) looks inside my game: