- Home /
Jittery object motion
When the camera is still, all moving objects look like they move smoothly, but when the player (and thus the camera) move, they all appear to have an extreme jitter in their movement. This is using cinemachine to follow the player.
From what I've read, this is due to the fact that the player itself is jittering, causing the camera to do so as well. So my question is why is my player jittering? It has a rigidbody with interpolation on, all physics are done in Fixed Update, player movement is done by setting it's velocity which is smoothdamped, Camera is updated with Smart Update (Late Update and Fixed Updated had worse results). Idk what else I could do??
Interestingly, this wasn't always a problem in my game, so I don't know why it all of a sudden is? I haven't made any changes to player movement or camera or anything.
Is this game 3D or 2D, does it use materials for the objects, what is the ground made of, can you just give more information please? It is a little hard to help when there is not very much info available about the problem. How is your script doing the movement?
The game is 2D and the movement is done by setting the rigidbody velocity like this:
rb.velocity = Vector3.SmoothDamp(rb.velocity, targetVelocity, ref v_Velocity, smoothing);
And is this in the FixedUpdate loop then? Maybe try not calling SmoothDamp every update period if that's what you're currently doing; maybe use a countdown and only SmoothDamp about once per 5 or 10 updates, while still keeping the target velocity updated every loop. Also make sure the SmoothDamp smoothing time is shorter than the time between when you call it and when you call the next one; it's possible that your SmoothDamps are interfering with one another and there are many trying to go to different end velocities (which would certainly make it jittery). Hope that helps.
Answer by ahsen35813 · Sep 05, 2021 at 07:33 PM
Before you read on, my answer is not a definite answer. I am only suggesting things that might work.
Don't set the velocity of the player rigidbody, no matter how smoothly you apply the velocity. That's just a bad idea to do every frame. Instead, make use of the rigidbody's physics and apply force to move it.
Instead of using cinemachine, try creating your own camera implementation, like this for example:
//Looking around float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime; float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime; xRotation -= mouseY; xRotation = Mathf.Clamp(xRotation, -90, 90); cam.transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f); //Needs a gameObject cam which is your player's camera, which should be parented to the player gameObject.transform.Rotate(Vector3.up * mouseX); //This script should be attatched to the player