I have spent a couple of hours trying to solve a seemingly trivial problem in an efficient way. Preface: I have many years of experience with Unity and am aware of the common pitfalls related to camera animation.
When having a fast moving object driven by physics, having a camera closely follow the object leads to intense jittering.
Everything happens in FixedUpdate and I have tried lerping the camera both in FixedUpdate and LateUpdate. Both interpolation and extrapolation have been tried. Fixing the camera to the object in question (either via parenting or simply setting the position in LateUpdate) eliminates the stuttering but is not acceptable as I want a certain inertia to the camera.
Which leads me to the question.
Is the current physics implementation in Unity inherently jittery in a way that following a rigidbody too closely will reveal frame by frame inconsistencies?
Even though FixedUpdate runs on a fixed timestep (which Update/LateUpdate does not) I had expected the interpolation methods to leave me with a consistent movement.
As it stands I can think of two workarounds:
- Have a visual model follow the physics rig. It will be a tiny bit behind but this should not be visible. This way the camera will follow the stable (but “late”) visual model instead. I am confident this would work, but it adds overhead to the programming and rigging.
- Fix the camera to the physics object and implement my own stable routines to simulate the inertia.
I would be very thankful for some input on this. In particular from Unity devs or experienced members. Thanks in advance!