- Home /
Camera jitters / lag behind when jumping or falling
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
Answer by meat5000 · Jan 02, 2018 at 01:21 PM
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.
playerRigidBody.$$anonymous$$ovePosition(transform.position + myForward Time.deltaTime currentSpeed);
playerRigidBody.AddForce(-gravity myGravity playerRigidBody.mass);
playerRigidBody.AddForce(myGravity jumpForce jumpHeight, Force$$anonymous$$ode.Impulse);
All of those are in FixedUpdate and I follow my player in FixedUpdate but in the camera script. How do you suggest to modify them so that I get better results? Thank you for the previous answer I had some problems and I did not have enough time to continue on my game but now I am on track.
Answer by thenephalem · Jan 02, 2018 at 12:03 PM
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.
Grinding my brain on this for a while today. Shutting off "Interpolate:" was the trick. THANKS for pushing forward @thenephalem. $$anonymous$$uch appreciated.
Your answer
Follow this Question
Related Questions
Move a camera with Rigidbody velocity without jitter 1 Answer
How can I avoid jitter of house? 0 Answers
How to prevent camera jitter when moving my Rigidbody first person controller 4 Answers
Game not running properly on slow machines (low fps) 1 Answer
How can I pragmatically move a navmesh rigid body when changing scenes? 0 Answers