This is in late update, and I am moving my object in Update.
This is working fine, but as soon as I am trying to smooth out the movement using a Lerp, camera begins to jitter.
From what I understood it seems it is related to the Lerp function ( OR that we should not be using a point that is moving as the first parameter ? ), and since I am pretty new to dealing to camera movement, I am not sure how to do things right to fix it correctly without surcharging and adding non necessary stuff…
Yeah your use of “Time.deltaTime * 30f” is a problem. It should be a percentage of the full movement expressed as a value between 0f and 1f.
Generally you’d have two points you are moving between over several frames as you increase that percent value each frame. Though changing those points every frame like it looks like you’re doing is going to make it difficult to smoothly lerp between them.
So basicly we should never use Lerp for camera interpolation, but rather smoothDamp ? because even if I am having a value going from 0 to 1, the initial position we are initiating the interpolation changeanyway, so it’s absolutely useless in that situation
Is your camera following an object that is moved with physics? If so, that is the source of the problem, and the camera should run in FixedUpdate. See last section here.
Putting the camera in Fixedupdate() and also the movement of the object in Fixedupdate(), seems it fixed the jitter indeed… I do need the object movement also in Fixedupdate right ?
In any way thanks a lot for the explanation, that makes more sense
FixedUpdate function is used to do something on the physics update. You can do whatever logic you want in there, it doesn’t have to be specifically physics operations with a rigidbody. But since we know that the character works with physics, then we also want to move the camera to face the character every time the physics system updates.
You can move your CharacterController in Update with no problems at all if you are not moving it using forces but using his Move or SimpleMove functions.
Yes, you can use Lerp for camera interpolated movement. If you use your current position as start position of the lerp and a constant alpha value (like 0.1f) what you get is a smoothed movement with ease out. Thats because you are moving your camera to the target position a 10% of the distance on each call. So as you get closer to the target, that 10% becomes a smaller value resulting in that “ease out” curve.
So, if you move your character in Update (dont forget multiplying your speed value * Time.deltaTime!) and your camera in LateUpdate everything must look fine