Now for the fun part. In the main timeline, add this piece of code to frame 1 (there should only be one frame) to create multiple instances of your particle. Remember that all the previous code is attached to your particle and so will be duplicated with it, making each particle self-sufficient:
for (n=1; n<100; n++) {
particlename.duplicateMovieClip("particlename"+n, n);
}
// where particlename is the instance name of your particle. Mine is called Jeff.
You'll also need to change the initial xval,yval,and zval properties to random values, otherwise they'll all be in the same spot:
xval = random(500); yval = random(500); zval = random(500);
Now you should have 100 shiny new particles moving about as if they were in a 3D space! If you are using an older version of flash, the code assigned to your particle may not duplicate with the clip.. if this is the case, open your clip and attach your code to a movie clip inside that one.. and it will then definitely be duplicated. (remember to delete the code on the outer clip if you do this)
You may notice that your center point is in the far left corner at the moment. To change this to centre screen you need to add an offset value to your equations like this:
in the (load) section:
offsetx = 275; // this is the midpoint of your flash screen offsety = 200; // so is this
in the (enterframe) section:
this._x = offsetx + scaler*xval; this._y = offsety + scaler*yval;
You'll then need to adjust the random initial values to cater for the blank sides of the screen:
xval = random(500)-random(500); yval = random(500)-random(500);
so now the whole body of code attached to your particle looks like this:
onClipEvent (load) {
xval = random(500)-random(500);
yval = random(500)-random(500);
zval = random(500);
offsetx = 275;
offsety = 200;
speed=5;
f = 300;
}
onClipEvent (enterFrame) {
if (Key.isDown(Key.LEFT)) {
xval += speed;
} else if (Key.isDown(Key.RIGHT)) {
xval -= speed;
}
if (Key.isDown(Key.UP)) {
yval += speed;
} else if (Key.isDown(Key.DOWN)) {
yval -= speed;
}
if (Key.isDown(Key.SPACE)) {
zval += speed;
} else if (Key.isDown(Key.CONTROL)) {
zval -= speed;
}
scaler = f/(f+zval);
this._x = offsetx+scaler*xval;
this._y = offsety+scaler*yval;
this._xscale = 100*scaler;
this._yscale = 100*scaler;
}
If you notice some quirky behaviour then that's because some particles are travelling to a depth which is less than 0. To stop that just add this code where you're subtracting from zval:
if (zval>0) {zval-=5;}
Here's a quick 'game'/toy called SunKiller I made using this code:
Check back soon for the second article to follow, Rotation in 3D.

Wow, thanks so much for writing this! I’ve been meaning to learn this sort of simple 3D stuff for a long time now, so I’m glad that I can check that off my list. :) I’m surprised at how simple this is – not a dot product or transformation matrix in sight! I’d thought I would need to dig through my old computer graphics notes to figure this one out, but I guess not. Thanks!
I was just looking for an article like this! Thanks!
Hello!
A great article!
Take a look at :- http://mochiads.com/games/proximity-alert/
I wrote this game using exactly the same methods, however I restrict movement on the y-axis purely because of the gameplay (the engine does allow it). The asteroids and ‘flies’ (the dots that fly toward the camera to indicate speed) all use this method. In fact, the little demo here has given me an idea for a new game …. :-)
Once again, great article – Flash can do ANYTHING if you put your mind to it!
Andy
Andy, I don’t know if you’re looking for feedback on your game, but I’d strongly recommend reducing the camera rotation when you bank right or left. Until I lost and read the instructions I didn’t realize that you could move forward and back because I was having so much trouble trying to point myself where I wanted by moving left and right. I think most people will find the effect more disorienting and unpleasant than cool.
It would also be nice to have a key that takes you back to the menu, like Esc perhaps. Other than that, nice game, and an impressive amount of visual fanciness. :)
Interesting article. I more or less had a general idea, but I ignored things like the focal point, for example. Thanks!
This article talks about the new 3d tecnology http://www.lorenzgames.com/blog/Away3D_-_The_future_of_3D_Flash_Games