heres a nice code i put together for car movement…
Create a map MC with the instance name “land”;
Then Create an MC with the instance name car; and give it this;
onClipEvent (load) {
function adjust(v, threshold, maximum) {
vx = 0;
if (v<=threshold) {
vx = (v/threshold)*1.0;
} else {
vx = 1;
}
return vx;
}
_root.maxspeed = 25;
_root.takeoff = .2;
minslidespeed = 3;
reversepeed = -3;
steer = .08;
drift = .98;
speed = 0;
traction = 10;
vector = [0, 0];
this._x = Stage.width/2;
this._y = Stage.height/2;
angle = 1.5609317684435;
_rotation = angle*180/Math.PI;
}
onClipEvent (enterFrame) {
_rotation = angle*180/Math.PI;
LR = Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT);
if (Key.isDown(Key.RIGHT)-Key.isDown(Key.LEFT)) {
angle += LR*steer*adjust(Math.abs(speed), minslidespeed, _root.maxspeed)/10;
}
if (!Key.isDown(Key.UP)-Key.isDown(Key.DOWN)) {
speed *= drift;
} else if (Key.isDown(Key.UP)-Key.isDown(Key.DOWN) & !Key.isDown(Key.SPACE)) {
speed = Math.min(Math.max(speed+Key.isDown(Key.UP)-Key.isDown(Key.DOWN)*.99, reversepeed), _root.maxspeed);
}
if (Math.abs(speed)<.99/2) {
speed = 0;
}
if (Key.isDown(Key.SPACE)) {
speed *= .93;
if (speed>2) {
steer = .099;
}
traction = 50/3;
} else {
traction = Math.max(1, Math.abs((speed-10)/3));
steer = .08;
}
if (speed<0) {
traction = 1.0;
}
_root.land._x += vector[0] += ((Math.cos(angle)*speed)-vector[0])/traction;
//replace _root.land with your background, which will move
_root.land._y += vector[1] += ((Math.sin(angle)*speed)-vector[1])/traction;
//replace _root.land with your background, which will move
}
Attached FLA and SWF;