Learn Create Your Own Split Screen

Next Page

The solution, in English, is "if the distance to go is less than how far we'd move in a single frame, then don't bother moving".

In code, we compare the distance to the velocity, and set the velocity to zero.

The only wrinkle is that we're dealing with both positive and negative values, and what we mean by "less than" is actually "nearer to zero". So we take the absolute (always positive) value of each before we do the comparison:

if (Math.abs(distance_x) < Math.abs(this.velocity_x)) this.velocity_x = 0; if (Math.abs(distance_y) < Math.abs(this.velocity_y)) this.velocity_y = 0;

Jitters fixed !