## Collision Detection Suggestions

Moderator
Posts: 613
Joined: 2004.09
Post: #1
I started work on a new game, im planning on something between a cross of Mealstorm and Mario Cart. Im doing it in a 2d Overhead view and I plan on racing/shooting mix.

My track consist of beacons which will let the player know where the track is since its set in space. The beacons on merely texturized quads along the x/y axis. Instead of getting too ahead of myself like a normally do I started to think about how I will handle collision detection. In my past games ive always done very simply bounds collision, but I cant grasp a way to do it that way for this kind of setup.

Im looking for suggestions for a method that I can use to test if I have passed through the "beacon path", The only thing that I can think of is drawing lines inbetween each point and testing against crossing that point, but I think that would require a lot of overhead and be rather slow.

The main problem I forsee running into is that each beacon will be space out from the last one so I cant test for hits on just the quads incase the player slips out inbetween the two. Is drawing invisable lines inbetween the quads and testing against that the best way to go here?

Thanks in advance for the insightful feedback.

Kyle Richter
DragonForged.com
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
create line strip going around the track in between the two beacons, every point on the line has a thickness, that maximum distance that the beacons are at.. that way the track and get wider and thinner.
for detecting if someone's off the track just see if the center of your ship's smallest distance to the line strip is greater than the thickness at that point,
an explanation of the math's is here:
http://astronomy.swin.edu.au/~pbourke/ge...pointline/

Also, you will probably want to divide the track into parts so you're not doing the long equation with so many line segments at once.

Sir, e^iÏ€ + 1 = 0, hence God exists; reply!
Sage
Posts: 1,487
Joined: 2002.09
Post: #3
So you have to pass between pairs of beacons that mark out the track? I'd just go for an extra simplistic approach and check the distance of the player against the center of the beacon pairs.

If you want it to be extra specific and actually make them pass between, you could check the collision of two line segments. One between the beacons and one from the players current position to his previous position.

If you actually want to make it like a track, do what unknown said.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Moderator
Posts: 613
Joined: 2004.09
Post: #4
Yea im gonna toy around with Unknowns suggestions because you can pass right up aganist a beacon and not be out of bounds.

What im gonna do is draw a line between each beacon and test for a collision along that line, that seems to be the easiest way of doing it so far. Im sure I will need to ask a followup question sooner or later but so far its going well. Thanks guys.

Kyle Richter
DragonForged.com