A Flash Developer Resource Site

# Thread: Collision Problem (racing game)

1. ## Collision Problem (racing game)

Hey, I'm new here, and I'm also fairly new to flash, I am having a problem with making collision boundries in flash, and I want you help... here is what I have so far... The instance "land" is the boundry, this script is on the car.

onClipEvent (enterFrame) {
//This code will advance the car forward.
if (Key.isDown(Key.UP)) {
speed += .5;
}
// This will make the car go backwards
if (Key.isDown(Key.DOWN)) {
speed -= .5;
}
//The car will start to slow down after the speed of 10
if (Math.abs(speed)>5) {
speed *= .5;
}
// This will change the angle of the car
if (Key.isDown(Key.LEFT)) {
_rotation -= 4;
}
if (Key.isDown(Key.RIGHT)) {
_rotation += 4;
}
// here is where the hittest is for the boundary
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;
}
}

My problem is, when I hit the boundry straight on, It works, but when I rotate on the boundry, I can go right through it with the car. I want a way so that the car can't rotate on the boundry, or if I can't do that, a way that even if the car does rotate, it can't go through the wall.

3. why not post yoru fla here so we can have a look..is the boundary an an angle or is it horizontal or vertical?

4. The boundry is both vertical and horizotal... it a square on the inside of the track... I will upload the FLA soon...

5. ok.. her is the link.... http://media.putfile.com/Racing-Game69

The boundry is what is keeping your from were the logo is... see how the "car" is over hanging it?

6. Actually, no, it barley hangs over it at all. That isnt a collision problem, your just being fussy

7. come on, it is for school... I want it perfect... isn't there a way so that it stops right were the black starts?

8. Post the FLA then.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap