Fixed camera follow stutter

hi all!
I have this issue: I have a camera placed into a fixed position and I need that follow (only rotating) the player.
I made this code:

var dir = target.transform.position - camera.transform.position;
var wantedRot = Quaternion.LookRotation(dir, Vector3.up);
camera.transform.rotation = wantedRot;

and works…
now I wish to manage a smooth rotation, to avoid a rigid rotation between camera and target: so I made this:

var dir = target.transform.position - camera.transform.position;
var wantedRot = Quaternion.LookRotation(dir, Vector3.up);
camera.transform.rotation =
Quaternion.Slerp(camera.transform.rotation, wantedRot, Time.DeltaTime * rotationDamping);

and it works, but the target stutter…
I tried to place the code in the LateUpdate, in the FixedUpdate, but seems that FixedUpdate is better, but not completely solved

I have an idea, but I don’t know how to fix:
should be that for example wanted rot is 10, and with Slerp I get a rotation of 4, in the next frame, the wanted rotation should be 12, but I start from 4, and so I made a Slerp with 8 and not 10 like before, and maybe the next frame is increased and this cause a stutter

did someone help me?

thanks in advance!

The stutter will depend on how fast the target is updating compared to your camera update. For example, if you update the target at 45fps and the camera at 30fps you will get a stutter effect.

It should work if you update the target in Update() and update the camera in LateUpdate(). That means they are both updating at the same frequency but the camera is updating -after- the target has moved.

1 Like

thank you @tonemcbride !
I had a problem on my game and I tried to test in a simple scene, using the Cinemachine samples,
the update is on Update function, so should not be different

and the LateUpdate seems to be the worst situation

If you have a test project you can post a link to it and I can have a look on Monday if you can’t get it working.

If you’re getting stutter, it will 99% be related to using LateUpdate() on the camera. If you’re using
transform.LookAt(pos);
it will never get the pos in sync with Update()
It sounds obvious, but stick any transforms for the camera right at the end of LateUpdate. :wink:

thank you for all…
in my test seems that if I use LookAt works fine, the stutter appears when I try to smooth the movement with Slerp or Lerp

here is the sample I made…

move the character with wasd

thank you for all