# Collision Problem (racing game)

• 03-25-2006, 10:13 AM
widger5000
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.
• 03-25-2006, 11:41 AM
widger5000
• 03-25-2006, 11:57 AM
silentweed
why not post yoru fla here so we can have a look..is the boundary an an angle or is it horizontal or vertical?
• 03-25-2006, 12:06 PM
widger5000
The boundry is both vertical and horizotal... it a square on the inside of the track... I will upload the FLA soon...
• 03-25-2006, 12:10 PM
widger5000
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?
• 03-25-2006, 12:40 PM
corky§urprise
Actually, no, it barley hangs over it at all. That isnt a collision problem, your just being fussy :D
• 03-25-2006, 12:44 PM
widger5000
come on, it is for school... I want it perfect... isn't there a way so that it stops right were the black starts?
• 03-25-2006, 01:04 PM
corky§urprise
Post the FLA then.