Learn Create Your Own Split Screen

Next Page

We're going to make one more change. To make the method more useful, it's going to accept a parameter called speed, which will control how fast (constant speed) the sprite moves. Adding the parameter to the method:
MySprite.prototype.Move_Towards = function(target_x, target_y, speed) {

Making use of it inside the method:

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

Passing a value in the call to the method:

jelly.Move_Towards(mouse_x, mouse_y, 3);

Try changing the speed to something faster than "3".