Monday 1 February 2010

Flash Game: Collision Detection, what a bastard!

Yes the title states my feelings towards collision detection because it claimed about 20 hours of my life (only a slight exaggeration). I originally had it detecting a sort of wall around my track but I realised after ages that this would not work. So I set about lining my track with reectangles around the outside and using these few lines of code within my collision function over and over:

if (mc_car.hitTestObject(mc_topboundary)){
speed = speed/1.5
}


And here is an image showing my rectangles I used (they're the objects with blue outlines):



And now if my car went over the edge of the track it would be hit with a severe speed penalty and would not be able to travel anywhere any fast. This was mainly to stop cheats driving down the middle of my track.

Next I will describe perhaps the 2nd most important part of my game, the timer!

No comments:

Post a Comment