Learn Create Your Own Split Screen

Next Page

Now instead of setting the velocities equal to the distances divided by a fixed number (10), we'll divide it by the actual distance remaining. By virtue of algebra, this removes distance from the equation.

this.velocity_x = distance_x / actual_distance ; this.velocity_y = distance_y / actual_distance ;

Try moving your mouse or finger around, and see that the jelly now always travels at a constant speed.