Yes I have tried using interpolate on both the camera and the object (and both independantly) and this just makes it even more jerky I am sad to say.
Thanks Yorick, I look forward to seeing your method!
If you want smoothness, always update the camera in the update loop. FixedUpdate() runs on a fixed schedule, but Update runs on a variable frame rate. As such, the time between FixedUpdate() calls is variable and causes jerking.
The solution is to always make your movements either in Update() (if you don’t care about Physics) or in LateUpdate() (if you want to overwrite Physics). I’ve made numerous smooth cameras, and FixedUpdate() does not agree with them when frame rates drop below the frame rate limit or the frame rate is variable.
One particular note is that you should generally have the camera update in LateUpdate() if following something affected by Physics. The camera would move before the object or character, otherwise, causing jerkiness.
Thanks for the code Yorick, sadly (although I too don’t understand it fully) is what im looking for.
Although indeed that script does keep up with the ship, what im trying to do is to keep the lerp rather than with a set position.
The reasoning for this is to give a sense of rotation for when the ship turns, the camera taking time to catch up really lets the player see their ship turn.
Any suggetions on how to go about that? Im looking into it myself but not to much avail sadly.
@Yorick: True. I apparently misread the code. Still, the issue is related.
The frame rate is constant for FixedUpdate and variable for LateUpdate. When you lerp, you’ll have multiple frames of lerping for every frame of movement. (Or at least that’s what appears to happen, anyway) The number of frames of lerp is variable, so you end up with a terrible stutter.
In a case like this, you might be best off just assigning a velocity to the camera and making it a rigidbody as well. You can follow by mimicking the velocity of the ship until the camera is looking at it properly and the correct distance away. The only real tricky part would be getting the angular velocity correct.
Does this suggest to handle the camera just in fixed update too because it will then be driven by physics?
I’m playing around with the same issue. The camera displays choppy images when I handle the Camera movement in LateUpdate(). My race game project handles a lot of physics in FixedUpdate(). I tried already a few things like increase the time-stamp from 0.02 to 0.03 or increasing the solver iteration count.
However I can solve the problem with just disabling the Rigidbody Interpolation and handle all camera movement from the SmoothFollow script in fixedUpdate(). The whole thing starts to run just awesome smooth. I guess that the major drawback will at an later time performance if the game project got heavier populated.
Further suggestion how to sync Physics in LateUpdate() ?
The problem in this case is that the lerping won’t be constant even when multiplying by Time.deltaTime. The reason behind it is that the percentage of movement is not always the same as the percentage of movement multiplied by Time.deltaTime for the extra number of frames. If you move 5% once every 20 frames, that would give you a .95 remaining distance. If you move 5% / 20 frames every frame, you get a .9517 remaining distance. The disconnect causes the jitter.
You can usually use a set position relative to the object, though, which is generally smooth. Alternatively, you can smooth-move the camera using a rigidbody, which also works well. You’d basically assign a velocity and angularVelocity every frame that’s designed to get the camera to reach a certain optimum distance and difference in angle.
Update() or LateUpdate() would only really be useful in the assigning of a position relative to the object followed or when player input would affect the positioning of the camera. All movement based on Physics is best kept inside FixedUpdate() at a later line than the code affecting an object’s position or rotation.
I got rid of my choppy Camera movement in LateUpdate() trough an combined mesh that the camera is following. http://forum.unity3d.com/viewtopic.php?t=23900&postdays=0&postorder=asc&start=0. I placed in my Car Physics script things like wheel rotation or steering graphics also in LateUpdate() and the hole thing is just running smooth!