-
help with collision in racing game
hi,
im making a simple top down racer - ususal format the car is controlled by keys and drives around a track. the track is a MC called "collision" when the car hits the side of the track i want a hit test to occour and the car to bounce back. I have the following code but for some reason cant get the car to hit the walls?
id really apprechiate any help on this?
if (_root.collision.hitTest(this._x, this._y, true)) {
//if current position is inside the level_mc
_y += ySpeed*1.1;
//move back to previous position(plus a little)
_x -= xSpeed*1.1;
speed = -(speed*bounce);
//reverse speed, and lose a little speed based on bounce
}
thanks
-
Senior Member
Your code doesnt make much sense. It only applies to situation of car being on the track and you add ySpeed but substract xSpeed. I suspect you should use if..else statement:
if (_root.collision.hitTest(this._x, this._y, true)) {
//move normally
}else{
//bounce back
}
-
sorry i cant seem to get my head around what is wrong. If i attach the file is there any chance you could have a quick look? its strange because the car does bounce off the walls now but only sometimes.?
-
Amiga freak
An attached fla is the best help... if people bother downloading it that is . Always start with posting the code, if that doesn't help, attach the fla.
-
ok its 99% working now thanks,
the only problem is the hit test works when the front or rear of the car hits the wall. but you can hit the wall side on. (as you can skid) and go straight through it.
ANy ideas how i could wack a hit test on the side of the car as well?
if (_root.collision.hitTest(this._x, this._y, true)) {
//if current position is inside the level_mc
_y += ySpeed*1.1;
//move back to previous position(plus a little)
_x -= xSpeed*1.1;
speed = -(speed*bounce);
//reverse speed, and lose a little speed based on bounce
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|