Thread: Programming Collision Detection

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    University of Waterloo

    Programming Collision Detection

    Anyone here know about collision detection at all? I'm trying to make a program that has objects in it that will rotate around a central fixed point. I need to know how to be able to tell if I'm running in to that object, no matter what angle it's rotated at....

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001


    Bounding box based on the most extreme vertices... just make sure you rotate the bounding box's vertices constant with the way you rotate the object.
    "He who makes a beast of himself, gets rid of the pain of being a man." Dr. Johnson

  3. #3
    Registered User
    Join Date
    Jan 2003
    There are a lot of ways to detect for collisions in 2D. The basic way is to see if the point, or box, is inside a bounding box. This is the fastest method.

    You can do it another way, my favorite. You find the center of the sprite (width/2, height/2) and use (width/2) as the radius. That way you have a circle. You get the point in question, find the distance from the cetner point (pythagorean's theorem) and if it's less than or equal to the radius: collision! This is just a bit slower, but it looks A LOT more accurate when you're playing your game.

    You can also test for bit-collision between the pictures of the sprites. Just draw their masks on top of each other and see if they collide. Really CPU intensive. It's recommended that you first use a bounding box test. If it's true, then do this, if you want. This is the most accurate test.

    If you're using polygons, chances are the library you're using, like DirectX, has collision detection functions. Find them and figure out how to implement them.

    If you're using 3D, all this gets just a bit more complicated. You'll have to think in another level....

  4. #4
    Registered User
    Join Date
    Jan 2003
    Also, to reduce speed, make collision rules. For example, enemy missiles can't hit enemies. Friendly fire can't happen. Things like along those lines. This reduces the ammount of collision tests you need to perform.

    Say you had 5 baddies, 3 bad missiles, you, and your 2 missiles. If you tested everything, you would have (n^2-n) tests, or 110 tests. But if you decided that baddies can't hit each other, you can't get hit from your missiles, and that missiles can't hit each other, you would only have (2 your missiles * 5 baddies + 1 you * 3 baddie missiles), or 13 tests. As you see, the latter will be much faster.

    The speed of the collision detection is just half the story, minimizing the number of tests is the other.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Collision Detection Problems
    By Dark_Phoenix in forum Game Programming
    Replies: 1
    Last Post: 12-17-2006, 03:25 PM
  2. Collision Detection
    By Grantyt3 in forum C++ Programming
    Replies: 3
    Last Post: 09-30-2005, 03:21 PM
  3. bounding box collision detection
    By DavidP in forum Game Programming
    Replies: 7
    Last Post: 07-07-2002, 11:43 PM
  4. collision detection
    By DavidP in forum Game Programming
    Replies: 2
    Last Post: 05-11-2002, 01:31 PM
  5. Replies: 4
    Last Post: 05-03-2002, 09:40 PM