# Advanced Car Movement.(drifting, 360degree turns, Friction)

**URL:** <https://forum.kirupa.com/t/advanced-car-movement-drifting-360degree-turns-friction/153725>\
**Category:** programming\
**Created:** [July 4, 2005, 8:03am UTC](https://forum.kirupa.com/t/advanced-car-movement-drifting-360degree-turns-friction/153725 "2005-07-04T08:03:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathan99](https://avatars.discourse-cdn.com/v4/letter/n/96bed5/32.png) [@nathan99](https://forum.kirupa.com/u/nathan99)\
**Post date:** [July 4, 2005, 8:03am UTC](https://forum.kirupa.com/t/advanced-car-movement-drifting-360degree-turns-friction/153725/1 "2005-07-04T08:03:22Z")

</div>

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;

```auto

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** ;
