Making a 2D loop track

Topics: Developer Forum
Oct 3, 2009 at 3:45 AM

Hello all, your help is very appreciated.

What i want is simple: a loop track (like a roller coaster). Also (im just saying this for reference, its probably easy to do), it needs to be built with the mouse (like the mouse were a brush), and naturally, a body must ride it.

So, i imagine the best way to do this is for the loop track to be simply a static line with collision. The problem is that the car that is going to ride on it is going to collide first with the "top -> bottom" part of the loop, whereas it should ignore it and collide first with the "bottom -> top".

On my point of view, its like the "bottom -> top" and "top->bottom"  parts of the loop were in different depths (layers), and thus the body would collide only when in the same layer. Easy to say, hard to do. Assuming this is the best solution, do you guys have an idea on how to do it?

PS: I humbly assume you would suggest using collision group, but since the line is going to be one body only (or so i think) it sounds bad.

I hope i made myself easy to understand, please feel free to present a better idea if you find this one bad.

Best regards.



Oct 4, 2009 at 8:06 PM

If you need different behaviors of different parts of the track, the easiest way is to create several geometries. One huge geometry have a lot of disadvantages, but it pretty much depends on your game.

Remember that you also have the OnCollision event that you can use to create dynamic game logic. One solution to your problem is to somehow mark that the current segment the player is touching is on another layer and then cancel the collision if that is the case. Something like this:

private bool OnCollision(Geom geom1, Geom trackPart, ContactList contactList)
   if (trackDepthTable[trackPart.Id] == player.CurrentDepth)
       return true;

return false;

You would register this event (delegate) on the player geometry.