# Car movement problems

**URL:** <https://forum.kirupa.com/t/car-movement-problems/191104>\
**Category:** flash\
**Created:** [June 17, 2006, 6:46am UTC](https://forum.kirupa.com/t/car-movement-problems/191104 "2006-06-17T06:46:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detective223](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@Detective223](https://forum.kirupa.com/u/Detective223)\
**Post date:** [June 17, 2006, 6:46am UTC](https://forum.kirupa.com/t/car-movement-problems/191104/1 "2006-06-17T06:46:07Z")

</div>

Well… I attempted to use an old script I found on flash-kit (website) on my car for a game…

But the car doesn’t move, it only rotates.

```auto

onClipEvent (enterFrame) {
 if (Key.isDown(Key.UP)) {
 speed += 1;
 }
 if (Key.isDown(Key.DOWN)) {
 speed -= 1;
 }
 if (Math.abs(speed)>20) {
 speed *= .7;
 }
 if (Key.isDown(Key.LEFT)) {
 _rotation -= 15;
 }
 if (Key.isDown(Key.RIGHT)) {
 _rotation += 15;
 }
 speed *= .98;
 x = Math.sin(_rotation*(Math.PI/180))*speed;
 y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
 if (!_root.land.hitTest(_x+x, _y+y, true)) {
 _x += x;
 _y += y;
 } else {
 speed *= -.6;
 }
}

```

I was hoping that someone who knows actionscript better could help me out?

I also want it to rotate more smoothly, and kind of jerk like a real car would.

Test results with both the collision block and the car script:

The car rotates, but it doesn’t move.

Edit: Found a code based for Flash MX (Not 2004).

```auto

 onClipEvent (enterFrame) {
 //When key UP is pressed, speed is increased
 if (Key.isDown(Key.UP)) {
 speed += 1;
 } else {
 //When key DOWN is pressed, speed is decreased
 if (Key.isDown(Key.DOWN)) {
 speed -= 1;
 } else {
 //If UP or DOWN aren't pressed then the speed decreases
 speed *= .9
 }
 }
 //The car will start to slow down after the speed of 25
 if (Math.abs(speed)>25) {
 speed *= .6;
 }
 //Turns the car left
 if (Key.isDown(Key.LEFT)) {
 _rotation -= speed;
 }
 //Turns the car right
 if (Key.isDown(Key.RIGHT)) {
 _rotation += speed;
 }
 //Moves the car
 speed *= .9;
 x = Math.sin(_rotation*(Math.PI/180))*speed;
 y = Math.cos(_rotation*(Math.PI/180))*speed*-1;
 if (!_root.move.hitTest(_x+x, _y+y, true)) {
 _x += x;
 _y += y;
 } else {
 speed *= -.3;
 }
 }

```

[/font]Test results:  
The movieclip doesn’t do anything on keypress.

What changes on these need to be made to make it work?

I saw an example of the outcome in a SWF file, and it worked better…

But it won’t work for me.

Edit again:  
Fixed:

```auto

onClipEvent(load)
{
 speed =0 ;
}

```

Now it works fine:  
 ![](http://i44.photobucket.com/albums/f43/Person99_please/car.swf)  
 ![](http://i44.photobucket.com/albums/f43/Person99_please/car.swf)

Edit: The image is broken, the URL is: [http://i44.photobucket.com/albums/f43/Person99\_please/car.swf](http://i44.photobucket.com/albums/f43/Person99_please/car.swf)

I also have 2 other questions though…

1. How can I have cars chasing the movie clip, like police cars chasing the one seen above?

2. How can I have collision, like you hit a wall, and it brings you to a different frame?

3. How can I have other cars moving around, and if you hit them, you actually HIT them?
