- Home /
[Advanced] AddForce Jitter
I've struggled with this question for years now and there is no good answer anywhere on the internet as far as I can tell.
I am simply trying to take in input from the player during Update() and then do this
Rigidbody2d.AddForce(new Vector2 (inputx, inputy) * Time.deltaTime)
During FixedUpdate(). Somehow, even when I release the input, at a certain point it starts jittering. My physics timestep is 0.2. Please, once and for all, how do I move the player character with AddForce with no stutter?
Is the player stuttering or does it just look like they're stuttering due to your camera setup? Have you tried moving the character with a detached stationary camera?
The platforms it moves across while stuttering do not stutter, but when I deactivate the following script I have it doesn't seem to jitter, at least not as much. However, every answer I find for smooth camera does what I'm doing: get the position of the player and camera in update, then update the camera's position with a lerp in LateUpdate().
I'm extremely confused.
Answer by Jehutyver10 · Sep 06, 2019 at 06:31 PM
I solved it: The answer, once and for all, is to put the camera's tracking method in FixedUpdate since the force is being added in FixedUpdate; this will make the two actions synchronize.
At long last, I have an answer. Future frustrated devs, gaze upon my struggle and learn!
Answer by Pangamini · Sep 06, 2019 at 08:32 AM
Time.deltaTime is a time difference between Update() calls. If you are applying the force in FixedUpdate(), you should use Time.fixedDeltaTime.
This won't change anything and isn't recommended since Time.deltaTime will already return the right delta time value depending on where it's used. See fixedDeltaTime:
For reading the delta time it is recommended to use Time.deltaTime ins$$anonymous$$d because it automatically returns the right delta time if you are inside a FixedUpdate function or Update function.
Thank you for your answer but this follows the exact pattern I found trying to answer this question:
Someone asks how to remove jitter
Someone posts a solution.
Someone else says why that solution won't work.
The question remains unanswered.
I hate to be a bother but do you have any other possible solutions? Thank you again.
You can try to set the Rigidbody2D's "Collision Detection" mode from "Discrete" to "Continuous".
Your answer
Follow this Question
Related Questions
Simulate perfect circular motion with addforce 0 Answers
Hinge joint 2d combined with relative joint 2d jitters with increasing linear offset 0 Answers
AddForce not moving object after instantiate 1 Answer
Unity Settings To Prevent Jittering? 0 Answers
AddForce to RigidBody2D on the same frame as SetParent(null) causes small jitter 2 Answers