- Home /
Jitter on 2d movement along the y-axis
Hello. I have a sprite in a 2d that I want to move at a constant speed down a long the y axis. My object settings and code are below:

// In BodyPart.cs
public void FixedUpdate() {
Vector3 pos = transform.position;
pos.y -= 2f * Time.deltaTime;
transform.position = pos;
}
I have tried only setting the velocity of the rigidbody, but the jitter persisted. I have also tried moving the update code to LateUpdate and just Update, but this also does not fix the problem. The jitter is seems to be small and somewhat constant. What is the best approach to remove the jitter and have the objects move down smoothly.
Answer by KBEK · Jun 30, 2016 at 05:22 PM
Seeing as you have a Rigidbody2D, the best way to go about creating "smooth" movement would be to use the "AddForce" function. It may also help to use Time.fixedDeltaTime instead of just deltaTime. Last thing I would suggest is to try building and running as this may help keep your framerate at a consistent level.
As a matter of fact, it is rather critical to use fixedDeltaTime in the fixed update loop. As the Unity documentation says, it is possible for the FixedUpdate to be called multiple times before another Update is called. Therefore, the deltaTime will be the same over multiple FixedUpdates.
OP, using fixedDeltaTime alone should help quite a lot.
Your answer