Acceleration, Friction, and Wrapping

Create Friction

This project is really coming along. We'll continue to push the math equations and add some friction into our movement. Space Friction!

We can continually pull down the ySpeed variable by multiplying times a number less than 1. Instead of racing on into infinity, the ship will slow to a stop.

Let's say ySpeed = 20. Before moving the ship, multiply ySpeed times .5:

20*.5=10;

ySpeed=10, and the ship moves 10 pixels. Now we multiply 10 times .5:

10*.5=5;

ySpeed=5, and the ship moves 5 pixels. This continues until movement is imperceptible... the ship slows to a stop.

To be honest, .5 is pretty aggressive, so let's start with .9 instead.

Declare a variable called yFriction with Number data type:

ySpeed Actions

Now we'll multiply ySpeed times yFriction:

Test it out.... it should function like this:

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

Does it work? Try combining those last two statements:

ship._y+=ySpeed*yFriction;