The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

2D Racing game Collision detection RRS feed

  • Question

  • Hey everybody I just finished my first game ever SuperSoldier(now in the marketplace) which is a 2D shooter . Now I wanted to take on more of a challenge with collision detection. See with the 2D shooter I did collision detection between bullets and the enemies or bullets and the player. Then i cheated a little by avoiding collision detection with the stage itself. Instead i used a clamp to keep the player within bounds. But now im ready to try to take on more of a collision challenge.

    So my question is if anyone can give me an idea on how to do collision with the edge of the racetrack in a 2D racing game USING TiledMap. Im going to draw it as if it was first person, so you can only see the steering wheel, drivers hands, and the front of the go-kart. So im thinking i should make a rectangle around the visible part of the car and test that against the track?

    I have read that i could use colors as the boarders? would this consist of giving the property of the times in TiledMap a color? Would this mean i should have a nested if statement? lets say if the tiles color is red, then its colliding with the edges of the racetrack. (example below)



    if( == "red")



    would this be sort of the way to do it? any suggestions or tutorials on 2D race collision is greatly appreciated. Thanks for reading everyone. Have a good day

    Tuesday, September 11, 2012 6:33 PM

All replies

  • Is your car going to rotate if not then you do ABB to ABB collision.

    if( obj1.pos.x + obj1.size.x/2  < obj2.pos.x - obj2.size.x/2)

    return false;

    if(obj1.pos.x - obj1.size.x/2 > obj2.pos.x + obj2.size.x/2)

    return false;

    if(obj1.pos.y + obj1.size.y/2 < obj2.pos.y - obj2.size.y/2)

    return false;

    if(obj1.pos.y - obj1.size.y/2 > obj2.pos.y + obj2.size.y/2)

    return false;

    return true;

    also if you have your sprites are using the Rectangle class then you can do rect.Intersects("Rectangle to pass in")

    Tuesday, September 11, 2012 9:30 PM
  • Thanks for the reply, my sprites are gonna use the rectangle class. Since i was going to make the map using TiledLib, I was thinking i could make a loop assigning the rectangle to the tiled that im next to. im just not sure on how to access those tiles in the TiledLib
    Wednesday, September 12, 2012 3:46 AM