Cinemachine stutters when following a Rigidbody

Hey,

I have an object that is being moved by setting its velocity. The Rigibody doesn’t have interpolation set. Meanwhile I have a Cinemachine Virtual Camera set to Transposer (Lock to Target No Roll) with some dampening applied and follow offset. The Aim is set to Hard Look At

Now my issue is that the camera is stuttering quite a bit. At first I thought it was the object itself but when I switch to the scene view, the object is moving smoothly and the camera seems to jump around.

I tried to switching update modes on Brain to various combination but it didn’t help. Same with Standby Update.

Any idea what can I do to get it to smoothly follow its target without this stutter?

Thanks.

1 Like

Standby Update is not relevant here.

If you set the Brain’s Update Method to Smart Update, then play the scene and look at the virtual camera’s inspector while the game is playing, what text do you see here?

5413380--550005--upload_2020-1-27_13-34-58.png

2 Likes

It says Fixed Update

Edited: corrected the update method it was using.

It says FixedUpdate? And it’s stuttering? That should not be, unless your target is moving unevenly. But you say it’s smooth.

Can you make a small project the reproduces this problem, and send it to me?

1 Like

That is what I see in the scene, it moves smoothly. Can I send the project (nothing more than the movement) in a PM please because it uses some paid assets from the store?

Thanks.

Sure. Delete the library folder before zipping, it will be much smaller

Thanks. Done and sent.

Had a look at the project, thanks for uploading.

I’m definitely seeing some stutter when playing in the editor. I believe that this is due to the discrepancy between the physics framerate and the render framerate. You will get aliasing, which is magnified by 2 things:

  1. Running in the Editor, which has a lot of extra overhead, making the render framerate more uneven. To get a more accurate idea of the situation, you should test a build of the project. When I do that, the stuttering is very considerably less.

  2. Using Damping on the camera. Unfortunately, damping is very sensitive to uneven frame rates, and the stuttering will be amplified by this. One way to mitigate this is to reduce the aliasing by increasing the physics framerate. When I changed the Fixed Timestep (in ProjectSettings/Time) to 0.01 it was quite smooth in the build.

On a side note, changing the vcam’s Aim to Composer (with default values) made the camera very sweet.

6 Likes

Thanks a lot for the information. I think I’ll go with the Composer for now given it feels very smooth and good. But is there anyway to fix this in editor? It is very annoying to test with this jumping behavior the camera has.

That said, how can the editor mess up the smoothing so much? Nothing drastic is running that it takes so much time to render things or am I misunderstanding what you meant?

A shorter fixed timestep definitely helps in the editor too. Don’t make it too short, or you’ll kill performance.

The editor is a big complex program and it does lots of stuff, even if there’s not much in your scene. The build, on the other hand, is 100% focused on the game.

Smooth camera movement with an uneven framerate is a hard problem: because it’s the camera, any little glitch in its smoothness results in a hugely visible artifact, which our human brains are very much tuned into detecting. Putting some effort into guaranteeing a smooth framerate would be a rewarding investment.

Update: I thought of something this morning and had another look at your project.

Your player is being driven on the physics clock, but your script is tinkering with the velocity on the render clock. That’s a problem. So I changed PlayerInput.Update() to PlayerInput.FixedUpdate(). Then, everything was perfectly smooth in the editor, even with the physics timestep at its original value of 0.02. Setting the timestep smaller was just covering up the real problem.

You can even increase the timestep further and, if you want, you can enable rigidbody interpolation on the player to smooth it out. It all works quite well.

The take-home message is that you have to be very careful with physics-driven objects to consistently alter the movement only in FixedUpdate, never elsewhere. Otherwise you’re liable to get judder.

7 Likes

I was going to post about it being smooth when I was moving the object using Transform.Translate then I thought, maybe this is an Input issue given I forgot to change that part. Then I came in here to say this only to see you’ve spotted it. Thanks a lot for the heads up.

2 Likes

Hey great thread guys - helped with something I was doing too xx!

1 Like

Agreed, incredibly useful :slight_smile: In my 2D project, moving the RigidBody2D in FixedUpdate() and turning on interpolation did the trick. Thanks!

Thank you so much! This fixes all my problems! And prompts to you for making the Cinemachine, my brother! I learned a lot by reading the source code of the cinemchine :slight_smile:

2 Likes

Sorry to necro, but i can’t figure this out. It says "Fixed update"but it stutters a lot on vertical movement. I tried turning off the old script i had that was altering the camera’s position as well as freezing the player’s movement, but it still stutters. Pretty sure i’m not taking camera input from any other scripts, it’s strange…

Did i set one of these settings wrong? If i change the decel/accel time it doesn’t seem to do anything.
8840554--1204513--upload_2023-2-28_18-1-19.png

@Mashimaro7 What is the Update Mode setting of the CM Brain?

1 Like

Oh, i didn’t realize there was settings for that on there. It was smart update, i changed it to late and it fixed the stutter, thanks!

1 Like