Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Cinemachine - Crazy jitter

Discussion in 'Cinemachine' started by Shapefarm, Apr 12, 2017.

  1. Shapefarm

    Shapefarm

    Joined:
    Dec 10, 2014
    Posts:
    17
    Hey guys,
    I'm getting a looot of jitter on the aim module. I have a very stable frame rate well over 60fps. Changing the dampening on the soft borders doesn't help. I also tried changing the script execution order to no avail.

    I'm using the latest Cinemachine with Unity 5.5.2f1. Any ideas of what might be the culprit?

    Here's a video showing the problem. It's just a cube being moved mathematically between two points over a completely random backdrop.

    https://dl.dropboxusercontent.com/u/1593461/AimJitter.mp4

    Cheers,
    Thom
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,727
    If target is a physical object, be sure to enable interpolation on the actual object itself. It looks to me the object is jittering, not the actual camera.
     
  3. Shapefarm

    Shapefarm

    Joined:
    Dec 10, 2014
    Posts:
    17
    Hi Hippo,
    The object just has a "procedural" animation generated from a script. It moves perfectly smooth (checked that by double F to follow objects in the editor). I haven't tried it on a physics object yet, but I'll do that asap. Also, a physics object moving that jittery would completely mess up PhysX as I guess you guys are aware of ;)

    I also tried it in Vane on our main character, getting the same jitter. It's very pronounced for objects moving in a straight smooth line. I thought the problem with trying it in Vane was that we have a lot of logic, which is why I tried it in a completely empty project (together with the new post effect stack).

    I'm definitely not ruling out any issues with the actual Unity version so I'll try it at home on 5.6.
     
  4. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,727
    It does seem like a problem then! @AdamMyhill will no doubt know far, far more than I :D
     
  5. mikew_unity

    mikew_unity

    Unity Technologies

    Joined:
    Sep 27, 2016
    Posts:
    121
    To me that does look like the object is jittering - the background is translating perfectly smoothly in your video. will ping the team but the camera movement looks pretty smooth...

    how are you moving the camera itself? is this using the transposer settings in cinemachine or something else?
     
  6. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    341
    Hi @Shapefarm The jitter problem comes up quite often. We have a discussion on it going on in the CM v1.5 thread with all the information.

    The short answer is that Cinemachine doesn't jitter, your object is jittering. When you frame the camera to it or lock a camera the jitter isn't noticeable because the camera is jittering with the object and it totally hides it.

    The jitter on the object is caused by spikes in delta time and/or the interpolation method of your object.

    That said, Cinemachine isn't cool with high-frequency jittery objects, it kinds of freaks the camera out. The way we are doing our damping is really sensitive to frame rate spikes and jerky interpolation. We can do a way better job of that and we're looking at changing the way our damping works to account for jittery objects since they're pretty common in Unity.

    As a test, make a new CM camera, no transposer or anything just have it sit somewhere in the world, target the cube and set the damping to 0,0 and set the composer to not have any dead-zone - hard lock the composition to it. I bet the jitter 'disappears'. It didn't actually go anywhere, it just is now hidden due to the camera being perfectly synched to the jitter.

    Check out that thread for more interpolation information. Try some of those ideas on your end and we'll see about bomb-proofing our damping on our end. This problem needs to disappear.
     
    JackofTraes and bowserscastle like this.
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    @Shapefarm I'm working on making Cinemachine more tolerant of jittery targets. Any chance you could drop me a stripped-down project that has the jittery movement? It looks like a good use-case.
     
  8. Carpe-Denius

    Carpe-Denius

    Joined:
    May 17, 2013
    Posts:
    827
    Do you have some damping in your scripts? I had a smooth follow script as a camera target for cinemachine and I had the same kind of jitter. The jitter disappeared when I set cinemachine to directly follow the (root motion animated) player instead of following the smooth follow gameobject.
    It would probably be jitter free too, if you try using fixedupdate or lateupdate instead of update or vice versa, depending on when cinemachine updates.
     
  9. Shapefarm

    Shapefarm

    Joined:
    Dec 10, 2014
    Posts:
    17
    Hi and thanks for all the replies!

    Yes, i did some in depth testing today and the jitter does come from the object. It doesn't completely go away if you use interpolation on your rigid body, but it does help a lot (it's also quite expensive so only use it for hero objects Matt said and scowled). Animation is a lost cause. Using animation causes an incredible amount of jitter.

    I talked to Matt and Vic here about it and we had the same issues with our own camera system. We did however manage to solve it somehow, but i'm just a lowly tech artist/sound guy so @Gregoryl please send a mail to info@friendandfoegames.com to talk to our programmers.

    Also, @Gregoryl here's a repro case for you.

    https://dl.dropboxusercontent.com/u/1593461/Cinemachine_JitterBug.rar

    There are two scenes. One with an animated object (AnimatedCubeFollow.unity) and one with a physics object (PhysicsCubeFollow.unity). To test @AdamMyhill 's hard constraint idea there are two cams (one soft and one hard constrained) in the physics scene for you to try with.

    All the best,
    Thom
     
    Adam_Myhill likes this.
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    @Shapefarm Thanks a bunch Thom, much appreciated! I'll keep you posted on any progress I make on the issue.
     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    So the CinemachineBrain now has the option of updating in FixedUpdate or LateUpdate. @Shapefarm your scenes are butter-smooth with the brain on FixedUpdate, and in the AnimatedCubeFollow scene the animnation update mode set to AnimatePhysics. Thanks for providing the content!

    Note: only the virtual cameras are updated in FixedUpdate. The Unity Camera is still moved in LateUpdate, regardless of the Brain's update mode. If you have order issues because of the FixedUpdate, you can always set the CinemachineBrain's script execution order to be at the end.
     
  12. Shapefarm

    Shapefarm

    Joined:
    Dec 10, 2014
    Posts:
    17
    Sweet! Where can i get the update?
     
  13. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    409
    I think we'll have to wait until Cinemachine 2.0 for the update. But as I'm currently developing my tools I'm cool with waiting a few weeks. Anyway, I also can't wait to try the new version!
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    @Shapefarm @Alverik We've gone even better in 2.0: The brain now has a setting for SmartUpdate, which is effectively: do whatever the target does. If the target updates in FixedUpdate, then any cameras looking at it will also update in FixedUpdate. If the target updates normally, then so will the cameras that look at it. Even better, in Smart mode, you can blend between cameras updating on different clocks.

    You can still set the brain to update on FixedUpdate or LateUpdate, but SmartUpdate makes this unnecessary.
     
    Lazulite and Alverik like this.
  15. EvyBenita

    EvyBenita

    Joined:
    Aug 8, 2015
    Posts:
    4
    You're a lifesaver, that worked like a charm!
     
  16. Jjules

    Jjules

    Joined:
    Dec 25, 2012
    Posts:
    33
    Im having some interesting results with the new system, so I figure I'll just report it here. So following an object with interpolate set on, the following happens with the different Cinemachine update methods:
    • Setting it to FixedUpdate, the player is slightly jittery but the stage moves smoothly
    • Setting it to LateUpdate, the stage is moderately jittery but the player moves smoothly
    • Setting it Smart Update, its highly jittery to the point that it looks like an Earthquake when I move
    I find that very odd that Smart Update, which is essentially just setting it to Fixed or Late Update for you, would perform so much worse then using any of the settings manually. This is just a quick heads up post, but I can post more evidence if you need it
     
  17. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    @Jjules We've done some more work on jitter in the new version CM2.1 (available later this week). I'd like to look at your scene with the new version. Any chance you could zip me up a package showing the jitter?
     
    Alverik likes this.
  18. Jjules

    Jjules

    Joined:
    Dec 25, 2012
    Posts:
    33
    Huzzah, I was wondering when 2.1 was coming out! And I certainly can package it, the only problem is the game only support Xbox Controllers ATM. Would you like me to Scrape together a keyboard/mouse system before zipping?
     
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    yes please!
     
  20. Jjules

    Jjules

    Joined:
    Dec 25, 2012
    Posts:
    33
    I've added keyboard/mouse support, so here is the project file!

    https://drive.google.com/file/d/0B-3zFfwOEYifc3BBblhscUU4TU0/view?usp=sharing

    Mind you that the project is an online multiplayer one, so the character is a prefab that you can find underneath prefabs/resources

    also as a little update, I realized that the jitter in Smart Update was so extreme because the framerate was so high. When I add image effects (which lowers the framerate on my not-so-powerful computer), the jitter is much less pronounced, so that reaffirms what you said ealier
     
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    @Jjules Thanks I'll have a look at it later today
     
  22. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    @Jjules Thanks for uploading. The camera jitter is caused by the fact that your player is being animated both in FixedUpdate (via rigidbody) and in normal Update. That's a condition that confuses Cinemachine. You have to choose one or the other, and the SmartUpdate setting will update the camera at the appropriate time. But you can't do both.

    RigidBody.Interpolation is a common source of this problem. Turn it off.

    Cinemachine 2.1 (available today in beta) will issue a warning on your vcam's inspector when it detects this condition and the Brain's update mode is SmartUpdate.
     
  23. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,727
    So is that not compatible with cinemachine?
     
  24. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    As of this writing, Interpolate can be a source of camera jitter if the camera is targeting the interpolated thing.
     
  25. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,727
    Ah I see, good to know! Some people are unlikely to give up using interpolation but I can easily see them reacting by using proxy gameobjects or something if they have to. Thanks for the info :)
     
  26. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
  27. Jjules

    Jjules

    Joined:
    Dec 25, 2012
    Posts:
    33
    thanks for the response. I have a few questions. The first is, do we have access to the beta? Im dying to get my hands on 2.1
     
  28. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
  29. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    248
  30. Jjules

    Jjules

    Joined:
    Dec 25, 2012
    Posts:
    33
    @Gregoryl Thanks, im playing with it right now! But beyond that, im a little confused by your response. Im handling all movement with the rigidbody in FixedUpdate. Im rotating the character and controlling his Mecanim (on a separate character object with an animator) with update? Is one of those things the culprit?

    And beyond that, all I did was turn off interpolate and left my code alone in 2.1 and there's no jitter! So was this only a 2.0.1 problem?
     
  31. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    SmartUpdate on the brain looks at the target of each vcam (the LookAt or Follow) and tracks when its transform is altered. If it happens in FixedUpdate, then the vcam will also update in FixedUpdate. If it happens in Update or later, then the vcam will update in LateUpdate. This is true in both CM 2.0 and 2.1.

    The problem comes when the target's transform changes in both FixedUpdate and Update. CM won't mirror this, which means that the virtual camera may not be exactly keeping up with the target, which potentially could result in visible jitter.

    What rigidBody.Interpolate does is to add a little something to the transform during the Update cycle, in addition to what physics did during FixedUpdate, so it is violating CM's no-jitter requirement. That's why it's best to turn it off for CM targets.

    That said, it is also possible that the transform is modified in such a way that the vcam won't care (e.g. rotation is changing but the vcam is only responding to the position).

    In your case, Interpolation was definitely a problem, so turning it off was a good idea. There is also something else in your scene that's playing with the main character's transform during update, but if you're seeing no jitter, then maybe the changes to the transform are below the vcam's radar.

    A good way to protect the vcam from exposure to such things is to have your animation system modify a child of the vcam target. Since the vcam is following the parent object, changes to the child transform won't affect it.
     
    Last edited: Aug 30, 2017
    bowserscastle likes this.
  32. Jjules

    Jjules

    Joined:
    Dec 25, 2012
    Posts:
    33
    Yep, that's exactly how I have it set up. The actual 3d model of the player with all the animations on it is a child of the "Player" GameObject. Even without Cinemachine, that's just good practice

    And Interpolate made my game run like garbage anyways lol so thanks for the help!
     
  33. GamesByNemiz

    GamesByNemiz

    Joined:
    Feb 6, 2019
    Posts:
    7
    Are someone still watching this thread?

    I stumbled upon the thread, because I am experiencing jittering, when using Cinemachine for following my player around, and was hoping someone could help me out.

    I'm using Unity version 2018.3.2f1 and Cinemachine 2.2.8.

    My original setup is a 2D platformer with animations, particles and the works, but for testing this issue, I have made a completely new project, in which a character is moved across a ground with trees on it - while a Cinemachine camera follows the character. The trees are clearly not moving smoothly.

    http://gamesbynemiz.com/unity-cinemachine-jitter/

    The character is moved by setting the x velocity to 5.
    A Cinemachine Virtual Camera has been setup to follow the character with all default values.

    In such a simple setup, are the trees not supposed to be moving smoothly, or what am I missing?

    I can provide project files, if anyone thinks that could help, but it really is as simple a setup as could be:
    • Ground with a box collider.
    • Character with a capsule collider and rigidbody.
    • Cinemachine camera that follows the character with default values.
    • Character x velocity set to 5.
    • Treesprites in the background that jitter.
    :/
     
  34. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    This is not a camera problem, it's an animation problem. The camera is tracking the player perfectly. RigidBodies update at a fixed rate (fixedDeltaTime), but the render frame rate is variable. Since the rendered frames are unevenly sampled, the player will move at uneven increments, and so the background might appear to stutter if the camera follows the player exactly (which is what it's doing).

    Try turning Interpolation on in the player's rigid body.
     
  35. GamesByNemiz

    GamesByNemiz

    Joined:
    Feb 6, 2019
    Posts:
    7
    Okay, that was a much faster answer, than I expected. Thanks!

    I just tried turning interpolation on, and get a similar result. With interpolation turned on, it does look like it's running more smoothly for a second or two, after which it sort of "catches up" to the jitter and jitters more extensively - then a few smooth seconds, then extensive jittering etc.
     
  36. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    Can you post an image of the vcam inspector, taken while the game is playing and the jitter is happening?
     
  37. GamesByNemiz

    GamesByNemiz

    Joined:
    Feb 6, 2019
    Posts:
    7
    Yes, but it doesn't change during the gameplay, neither before jittering nor after. I did notice your much earlier comment about a warning message, but haven't been able to see it anywhere.

    upload_2019-2-6_19-54-13.png
     
  38. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    Can you try this experiment:
    In your Player Settings, define CINEMACHINE_EXPERIMENTAL_DAMPING

    upload_2019-2-6_14-1-42.png

    (you may have to reload the project to make sure it gets swallowed)
    Then try again, with the interpolation on.
     
  39. GamesByNemiz

    GamesByNemiz

    Joined:
    Feb 6, 2019
    Posts:
    7
    It doesn't seem to change anything, but I'm also not sure, it was really swallowed. I first tried setting it, and then reloading the project, but that removed the value. Then I just tried setting it, keeping the settings open, while running the project, which didn't change anything.

    I have uploaded the project to my site, if you need it - http://www.gamesbynemiz.com/internal/testing/cinemachine

    Or if you have further suggestions, I'm happy to try them out.
     
  40. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    Thanks for uploading. The problem has nothing to do with Cinemachine - you can just parent a plain camera to the character and you get the same result.

    Most likely it's framerate hiccups due to playing the game within the editor. I tried making a build and it was quite smooth.
     
  41. GamesByNemiz

    GamesByNemiz

    Joined:
    Feb 6, 2019
    Posts:
    7
    Alright, so just a build with interpolation? I'll give it a go.
     
  42. GamesByNemiz

    GamesByNemiz

    Joined:
    Feb 6, 2019
    Posts:
    7
    Yes, that did the trick. I actually had to restart my PC, before it really helped, but with interpolation on, it does really look to run smoothly now. Thanks :)

    This was however just a simple test project - now I'll have to see, if I can transfer the same steps with the same results to "the real project" ;)

    But now I know, it can be done. That helps a lot - thanks again.
     
    Gregoryl likes this.
  43. GamesByNemiz

    GamesByNemiz

    Joined:
    Feb 6, 2019
    Posts:
    7
    It also works in "the real project". Thanks for the help. You made my week!
     
    Gregoryl likes this.
  44. rtilton1

    rtilton1

    Joined:
    Jan 4, 2017
    Posts:
    54
    @Gregoryl I'm using Unity 2018.3.0f2 with Cinemachine v2.2.8 and using a CM FreeLook camera and have an insane amount of jitter. If I put a non-cinemachine camera as a child of my character it doesn't jitter at all... I've read above thread- and although it would seem the jitter is a result of my character not moving smoothly - the character doesn't look like it jitters at all with a normal camera as a child. My character that is the follow and lookAt target has no rigidbody. The CM brain is set to Smart Update.

    One fix I tried was to put my character controller movement code in FixedUpdate instead of Update. This seems to have made the CM cameras look smooth without jitter. Seems odd still after reading the above though - as I thought the SmartUpdate in the CM brain should let me do movement code in Update no problem.

    Let me know if you think there's a way to get this to work when keeping my code in Update. Happy to send over my project files if you send me a DM.
     
  45. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    A camera attached as a child of the target will never jitter even if the target animates erratically, because the camera - which is rigidly attached - jitters right along with the target (however, the background will jitter in these circumstances, but that is usually less distracting).

    Smart update will choose FixedUpdate as an update mode for cameras targeting a given target if and only if 100% of the target's transform modifications happen in FixedUpdate. If the target is a child of a RigidBody, that will affect its transform in the FixedUpdate cycle, so updating it in Update() will cause a mixed situation and create problems. From your description, it's likely that that's what's going on.

    You can prove that by looking at the vcam inspector while it's playing and jittering, and see that it's updating in LateUpdate. If you move your code to FixedUpdate and the jitters go away, you'll see that the vcam is updating in FixedUpdate.

    If turning on interpolation on the RigidBody doesn't fix the problem, then you'll probably have to move your code to FixedUpdate.

    Is there a reason why you need to have your update code in Update?
     
  46. rtilton1

    rtilton1

    Joined:
    Jan 4, 2017
    Posts:
    54
    Gotcha... I will put all my transform position movement code in FixedUpdate then. I need some of my code in Update for snappier procedural bone animations (in FixedUpdate it doesn't instantiate right for some reason)... Ideally I wanted to keep everything clean in only one Update loop, but it's no problem for me to split it up between transform and animation code...

    Appreciate the support Gregoryl
     
    Gregoryl likes this.
  47. LAKSHAYMAVIA

    LAKSHAYMAVIA

    Joined:
    Aug 28, 2018
    Posts:
    25
    It works thank you
     
  48. mackhack2015

    mackhack2015

    Joined:
    Aug 26, 2018
    Posts:
    3
    I was having the same problem and I started to read this forum and changing to Interlope on my object and setting the update mode for the camera to LateUpdate fixed my jitter
     
  49. flankey

    flankey

    Joined:
    May 25, 2018
    Posts:
    1
    Hello, I am experiencing problem too. For me Cinemachine is not jittery while player is moving at all, but only when "returning from lookahead" to default position when player stopped. Ive tried everything from different updates for cinemachine and player, interpolated rigidbody etc. nothing seem to make it behave differently.
     
  50. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    3,811
    Can you show a video of this? If it's lookahead-related then the update mode is not relevant.
     
unityunity