- Home /
How to prevent camera jitter when moving my Rigidbody first person controller
I have written a very simple Rigidbody first-person character controller. The controller is on a GameObject with a Rigidbody and Capsule Collider. A Camera is a child object of the Rigidbody object.
During Update:
The controller rotates the camera (vertical) with mouse input and rotates the GameObject (horizontal)
Gets the input from the keyboard (WASD) and stores it. (I know that inputs are updated on Update so this is where I should get input)
During FixedUpdate:Transform the input into a world space Vector3.
Apply acceleration to the Rigidbody in the direction of the transformed input.
This controller works "fine" as far as moving the character around as expected and looking around etc. But when moving sideways at the same time as turning the camera horizontally, I notice this significant jittering in the motion of the camera.
I am fairly certain this has to do with the asynchronous timing of Update vs FixedUpdate, as when I move the character during Update the problem does not occur. But I'm making a Rigidbody controller so I need to use FixedUpdate.
Is there anything I can do to fix this?
Answer by lgarczyn · Dec 05, 2019 at 11:16 PM
Simply enable interpolation on the rigidbody. This will make it "lag" behind its real position, but will vastly improve jitter.
A kinematic rigidbody can have even better interpolation, but has to implement its own velocity and collision checks using raycasts.
I have no idea way, but for me the right result was archived when I did exactly the opposite, I changed "interpolated" to none and it worked.
Enabling interpolation worked magic for me.
$$anonymous$$y issue was the camera was following a ball. When I rotate around the ball while it is moving in slow motion there is no jitter. But when I leave slow motion and try to rotate around the ball while it is moving, jitter happens.
$$anonymous$$y thanks to you. I spent 3 hours trying to figure out how to solve the issue, and it was just a simple click.
Answer by JakovHStudios · Aug 18, 2021 at 01:02 PM
Hi there @Kwergan , I know that this is a very late reply, but this worked for me:
If you move the rotation of the player through your camera script like this:
player.rotation = bla bla //--in my case Quaternion.Euler(Quaternion.Euler(0, yRotation, 0);--
You need to change it so that you rotate the players Rigidbody, like this:
player.GetComponent<Rigidbody>().MoveRotation(Quaternion.Euler(0, yRotation, 0));
If you, or someone else read this, but i didn't really explain it well: Let me know!
well its work for me but not totally 100% smooth maybe i can put blur effect to make it smooth
Answer by EagleDeveloper · Aug 07, 2020 at 10:52 AM
Hey @Kwergan ,
Sorry for the late Reply
Actually, I had the same problem, It actually is very simple.
Just Multiply your horizontal and vertical axis input with Time.fixedDeltaTime, just like this:
x = Input.GetAxis("whatever") * Time.fixedDeltaTime;
y = Input.GetAxis("whatever") * Time.fixedDeltaTime;
I was having an issue with characterController, and it was the fix. Thank you very much!
Answer by ProfMonkey07 · Jul 25, 2020 at 11:14 PM
put the function moving the camera in fixedupdate or lateupdate maybe
Your answer
Follow this Question
Related Questions
Gravity not working 1 Answer
Move a camera with Rigidbody velocity without jitter 1 Answer
Having trouble turning a Transform movement into a Rigidbody force. Code included 1 Answer
Character and Camera motion smooth in Editor, but jitters in Build 1 Answer
Rigidbodies get huge amount of velocity when clipping into other Rigidbodies 2 Answers