Here is a tutorial on how to make your character, object, car (or whatever you want!) to accelerate and decelerate to add a bit more life to the object.
In this first example we will be using a car which we will make. Hopefully you know the basics of flash if you dont here is a link to the basics.
Make sure your car has two wheels, one with the instance name “wheel” and the other “wheel1″ and a base called “car”.
So here is my car:-

Ok now we have the car lets get down to the scripting. In the first frame add this code :-

Here is what it means :-
lines 1 - 6 = Are setting up variables indicating the speed, friction, and a blank variable so we can add to it.
lines 8 - 14 = Setting up movement for the car - adding variables to the blank variable making the speed feature.
lines 16 - 22 = Adding the values to the x axis and rotation and making friction work. The way the friction works is by multiplying by a number which is of a 0.1-0.9 value. It slowly decreases making the car Decelerate. The way the acceleration is made is by having a blank variable we can add to it, to make an increasing number making it faster and faster aka accelerate.
Here is the finished .fla and .swf file.
Happy game making!!
Joshua Beynon
josh.thedude@hotmail.com
Did you find this tutorial useful? Do you have any questions about the tutorial or a request for another? Please sign up now and post your comments below!
Did this post help you? If so help us continue to grow and Digg this page or Share on Twitter!
If you haven't already, sign up to our RSS feed or register to recieve updates direct to your email!








Hi,
This is a very good example of accelleration and deaccelleration.
Thanks
Hey there. Great tutorials, I’m glad I found this site!
I’m a beginner in flashprogramming, so correct me if I’m wrong..
I was just wondering.. Even though the “wheel._rotation += cs*2;” seems to work just fine on your example, wouldn’t it be more accurate to use the perimeter? Like this maybe:
wheel._rotation += cs/(wheel._width*Math.PI)*360;
I haven’t tried it myself, so I don’t know if it would work.