- Home
- Tutorials
- Flash
- Intermediate
- Car Movement
Car Movement
This article has been removed from your 'Articles to Read' list.

Wheel Trails
Philip Peralov
Philip is a Flash guru and a ActionScript freak. He has done a couple of projects, featuring games, programs, websites & cartoons. He's only 15 years old, but he well knows programing in Java & ActionScript and is a professional in Animating. In his free time he goes to the local High School :) in Bitola, Macedonia, Europe, where he lives.
Now, we'll program the car, so it can left a trail on the ground, made by the wheels. For that purpose we'll use the Drawing API. The drawing API allows you to draw lines and shapes with ActionScript and gives you the freedom to start an application with the computer equivalent of a blank canvas, on which you can create whatever images you wish. We need to know what we want to do with the drawing API.
In this case we want to make a wheel trail. So, we're going to use the car _x and _y properties to draw those lines. First we'll try to draw just one line from the center of the car. So let's start.
All the scripts goes to the car mc (short term for MovieClip). Create a mc for the drawing (we use mc instead the stage to draw, because like this we can change the depth property).
The new empty mc it's called "drawingMC" and it has a depth value of 1. We use swapDepths to make the car over the trail. Otherwise the car can (will) be under them.
Now under the enterFrame event add the following script:
Yeah, it works nice, but at the start the lines start from 0,0 coordinates. Fix that by applying this script under the onLoad event.
Next, we need to move the trail to the left or the right so it will looks like it's coming from one of the tires. We can't just use _x+2 or something like that, because the car rotates and the values need to change. That's why under the enterFrame event enter:
I'm not going to explain this script, because we already discussed this on page 2.
However, we're not going to remove the recently script _root.drawing.moveTo (_x,_y); and we're going to add something similar to the enterFrame event because when we gonna add another trail those two will get together.
Modify the script to something like this.
All we need to do now is to add the following script to the onLoad event and we're done.
We applied the same script to the onLoad event because otherwise the lines will begin with coordinates of 0, 0, and we sure don't want that :) And if you want to apply stronger trail when the car brakes, think a litlle yourself......It's easy.
The source file and this tutorial in .pdf are in attachments
In this case we want to make a wheel trail. So, we're going to use the car _x and _y properties to draw those lines. First we'll try to draw just one line from the center of the car. So let's start.
All the scripts goes to the car mc (short term for MovieClip). Create a mc for the drawing (we use mc instead the stage to draw, because like this we can change the depth property).
onClipEvent (load) {
var speed:Number = new Number (0);
_root.createEmptyMovieClip ("drawing",1);
this.swapDepths (_root.drawing);
}
The new empty mc it's called "drawingMC" and it has a depth value of 1. We use swapDepths to make the car over the trail. Otherwise the car can (will) be under them.
Now under the enterFrame event add the following script:
_root.drawing.lineStyle (3,0xeeeeee,100);
_root.drawing.lineTo (_x,_y);
Yeah, it works nice, but at the start the lines start from 0,0 coordinates. Fix that by applying this script under the onLoad event.
_root.drawing.moveTo (_x,_y);
Next, we need to move the trail to the left or the right so it will looks like it's coming from one of the tires. We can't just use _x+2 or something like that, because the car rotates and the values need to change. That's why under the enterFrame event enter:
xTrail = Math.sin (_rotation * Math.PI / 180) * 10;
yTrail = Math.cos (_rotation * Math.PI / 180) * 10;
xTrailCalculated = _x - yTrail;
yTrailCalculated = _y - xTrail;
I'm not going to explain this script, because we already discussed this on page 2.
However, we're not going to remove the recently script _root.drawing.moveTo (_x,_y); and we're going to add something similar to the enterFrame event because when we gonna add another trail those two will get together.
Modify the script to something like this.
xTrailCalculated = _x - yTrail;
yTrailCalculated = _y - xTrail;
xTrailCalculated2 = _x + yTrail;
yTrailCalculated2 = _y + xTrail;
_root.drawing.moveTo (xTrailCalculated,yTrailCalculated);
_root.drawing.lineTo (_x - yTrail,<span id="_de_spell_word_1">_y</span> - xTrail);
_root.drawing.moveTo (xTrailCalculated2,yTrailCalculated2);
_root.drawing.lineTo (_x + yTrail,_y + xTrail);
All we need to do now is to add the following script to the onLoad event and we're done.
xTrail = Math.sin (_rotation * Math.PI / 180) * 10;
yTrail = Math.cos (_rotation * Math.PI / 180) * 10;
xTrailCalculated = _x - yTrail;
yTrailCalculated = _y - xTrail;
xTrailCalculated2 = _x + yTrail;
yTrailCalculated2 = _y + xTrail;
We applied the same script to the onLoad event because otherwise the lines will begin with coordinates of 0, 0, and we sure don't want that :) And if you want to apply stronger trail when the car brakes, think a litlle yourself......It's easy.
The source file and this tutorial in .pdf are in attachments
Spread The Word
Attachments
21 Responses to "Car Movement" 
|
said this on 09 Aug 2007 6:06:16 PM CST
Can't see the wheel t
|
|
said this on 11 Aug 2007 1:34:28 PM CST
It wasn't finished ye
|
|
said this on 14 Aug 2007 8:13:40 AM CST
Good job, the car movemen
|
|
said this on 14 Aug 2007 10:01:32 PM CST
awesome work. this script
|
|
said this on 15 Aug 2007 7:35:17 AM CST
hey dude, your good! i li
|
|
said this on 18 Aug 2007 8:47:52 PM CST
great tutorial, its the f
|
|
said this on 20 Aug 2007 12:29:04 AM CST
nice work & nice script.
|
|
said this on 21 Aug 2007 10:08:41 AM CST
Whilst this is a good tut
|
|
said this on 23 Aug 2007 6:58:26 AM CST
Agree with Ian - nice tut
|
|
said this on 25 Aug 2007 3:31:42 PM CST
Sorry bout the .fla I'
|
|
said this on 22 Sep 2007 10:22:48 AM CST
your script is very used
thank u . |
|
said this on 26 Sep 2007 7:11:37 AM CST
Re your action script car
My 10 year old |
|
said this on 26 Sep 2007 4:20:38 PM CST
Great tutorial. However I
|
|
said this on 16 Oct 2007 5:32:01 PM CST
i could not get the tires
|
|
said this on 03 Nov 2007 9:46:48 AM CST
@rich
you'll go to t BTW gre |
|
said this on 21 Nov 2007 4:56:35 PM CST
Philip, great tutorial, a
|
|
said this on 14 Dec 2007 7:04:58 PM CST
Hey, great tutorial, I am
|
|
said this on 01 Jan 2009 6:05:58 PM CST
works like a charm. Works
|
|
said this on 06 Mar 2009 10:53:05 AM CST
Works great, until I real
|
|
said this on 24 Nov 2009 8:43:03 PM CST
Here is the wheel trail a
_r _root.dr xT yTrai xTrailCa y } onClipEvent (ente _root.drawing _root.drawing.line xTrail = Math.sin(_rot xTr yTrailCalculated = _y _root.drawing. } on _roo this.swap xTrail = Math.sin yTrail = Math.cos(_r } onClipEvent (enterFra _root.drawing2.li _root.drawing2.lineTo yT } |


Author/Admin)