I know that there have been numerous threads about this topic but still i find it difficult to comprehend the whole situation. I update the rigidbody’s velocity in the horizontal direction in FixedUpdate() and then I apply force (my own gravity) in the vertical direction also in the FixedUpdate() method.
In the CameraController script I use the following lines to update the position of the camera.
toPos = currentView.position + (currentView.rotation * new Vector3(0f, 2f, -2.5f));
curPos = Vector3.Slerp(transform.position, toPos, smoothFactor * Time.deltaTime);
And then I have in the LateUpdate()
transform.position = curPos;
transform.LookAt(currentView.transform, currentView.transform.up);
The result is quite smooth when running on a platform (no gravity) but the camera begins to jitter when I jump or the player is falling. I have spent too many hours on this problem and I will be really grateful if someone is able to explain to me how to fix this issue.
Best regards
Your friendly neighbourhood noob
I have finally found the problem. It was that my rigidbody’s Interpolate was set to Interpolate. I have changed it to None and all of the jitter/stutter when falling or jumping is now gone. I will definitely make further research on this topic. If anybody has any idea why this happens it would be wonderful. I make all of my physics in FixedUpdate.
It is usually inadvisable to directly modify velocity. It can make for some erratic behaviour. Jitter usually arises from differences of updates between FixedUpdate and Update. Timing of FixedUpdate is not really as Fixed as it may suggest and sometimes placing code in Update instead produces better results, creating better scaling of variables with respect to how the User views it from frame to frame.
Movement by direct Transform modification can also create some jittery results. A combination of the two could be asking for trouble. The results will be worsened at lower fps.
The reason why your character jitters in vertical whilst horizontal Velocity is being set is that Spamming a velocity component to 0f will cause that object to stop dead in that direction and then regain speed under the Physics Engines computational updates. This is why a lot of people end up with Player-characters that float like clouds when jumping.
When setting Velocity, make sure to first read off the Current Velocity x,y,z values and use those as a base for your next calculation, adding or subtracting a scaled amount, instead of hard setting values. This serves to add some (de)/(a)cceleration.