3D Racing Car Engine
[ July 14, 2003 ] by David Crawford, alias Percy Pea
This prototype was posted by PercyPea in the FlashKit forums and we think it really deserves some attention! Here is an excerpt of the discussion with some info and code. We also suggest you to follow the entire thread in the Flashkit forums at this address.


To get it working, simply copy the code into the first frame.
Then you need two movie clips, the first is easy, and is the mask section. Just draw a horizontal box (no outline) that stretches across the length of ur screen, and make it a couple of pixels tall. (the code changes its height so doesnt matter the exact size, i used 3 pixels though). Make the mask into a movieclip called 'mask', align it so its reference point is at the top left corner.

Now you need your ground texture. Import your bitmap texture, mine was 1000x1000 pixels, if u using lower res, just stretch it on the screen to approx 1000x1000.

With all the reference points for movieclips below, make em centered.

Then follow this exactly
Select the image, F8 it (make it a movieclip symbol), call it 'movepic' and give it an instance name of 'move'. (Instance name is the important one here.

Now select your new 'movepic' movieclip, F8 it again, call it 'thepic' and give it an instance name 'pic'. 'pic' being the important thing again

Finally, select the 'thepic' movie clip again, and F8 it, call it 'pic', dont worry bout instance name.

Right, now that you have both ur mask and image inside several depths of movie clips. delete them from the stage, and in the library, right click on both the pic and mask (one at a time) and go to linkage and tick the 'export in actionscript' thingeee. Use the default names of 'pic' and 'mask'.

adjust the ms value in the code to increase or decrease the quality. 1 being the best quality, but very slow, 3 being reccomended, and any higher faster, but poorer quality

If you want to adjust where the land actually turns around (rotation point) edit the 'pic' movieclip and just nudge up 'thepic' 10 or so pixels.

_quality = "LOW";
ms=3
//attaches ground and mask
// ms is set as the value u type in at the start.
for (a=1; a <= (180/ms); a++) {
	//grd = ground, mask = the mask movieclip
	grd = attachMovie("pic", "pic"+a, a*3+1);
	grd.pic._xscale = grd.pic._yscale=100;
	grd._x = 275;
	grd._y = 400;
	//the ground is scaled only once, when created. not on every frame
	grd._xscale = a*ms*10
	grd._yscale = a*ms*10;
	/// the below code happens on every frame for each bit of the ground.
	
	grd.onEnterFrame = function() {
		//the pic is rotated, but the 'move' symbol inside the pic is what is moved.
		this.pic._rotation = _root.rotation;
		this.pic.move._y += _root.cosness;
		this.pic.move._x += _root.sinness;
	};

	mask = attachMovie("mask", "mask"+a, a*3+2);
	mask._height = ms;
	mask._y = 200+a*ms;
	grd.setMask(mask);
}

//movement ripped from an earlier version of my GTA engine
onEnterFrame = function () {

	if (Key.isDown(39)) {
		_root.rotation = _root.rotation-5;
	}
	
	if (Key.isDown(37)) {
		_root.rotation = _root.rotation+5;
	}
	
	if (Key.isDown(38) and _root.speed<=20) {
	_root.speed = _root.speed+0.6;
	}

	if (Key.isDown(40)) {
		_root.speed = _root.speed-0.4;
	}
 
	if (_root.speed > 0.2) {
		_root.speed = _root.speed-0.2;
	} else {
		if (Key.isDown(40)) {
			// _root.speed = _root.speed-0.4;
		} else {
			if (_root.speed < -0.2) {
			_root.speed = _root.speed+0.2;
			} else {
				_root.speed = 0;
			}
		}
	}	
// calculate cos and sin for roads rotation just once every frame rather than in each
// road movieclip.
_root.cosness = _root.speed*Math.cos(_root.rotation*Math.PI/180)/2;
_root.sinness = _root.speed*Math.sin(_root.rotation*Math.PI/180)/2;
};


 
 
Name: David Crawford, alias Percy Pea
Location: U.K.
Age: 23
Flash experience: Over 3 years experience in the industry, on top of a BSc Honours Degree in multimedia design.
Job: Full time e-learning application developer.
Website: http://www.percypea.com
 
 
| Homepage | News | Games | Articles | Multiplayer Central | Reviews | Spotlight | Forums | Info | Links | Contact us | Advertise | Credits |

| www.smartfoxserver.com | www.gotoandplay.biz | www.openspace-engine.com |

gotoAndPlay() v 3.0.0 -- (c)2003-2008 gotoAndPlay() Team -- P.IVA 03121770048