collision detection

This is a discussion on collision detection within the Game Programming forums, part of the General Programming Boards category; I was working on my collision detection for my DBZ clone of Liero today, and I was presented with a ...

  1. #1
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738

    Question collision detection

    I was working on my collision detection for my DBZ clone of Liero today, and I was presented with a problem. For any of you who know Liero (which is much like Worms), you will know that the map is displayed like this:

    Background bitmap
    "Dirt" or deformable terrain bitmap
    "Rocks" or impassibles

    The background is a single bitmap blitted onto the screen. The "dirt" is also a single bitmap blitted onto the screen, but with several spots where it is transparent, so you can see the background, and the dirt can be deformed, so more of the background shows.
    The rocks cannot be changed. That is also the order in which things are blitted onto the screen.

    Now, keeping in mind how the map is displayed, here is how it is done in my DBZ clone:

    Background
    Foreground

    My game does not have a deformable foreground as of yet like Liero does, but basically everything in the background is the background, and everything in the foreground can be collided against.

    Now how would you do collision detection? Lets say you have a 20x25 character moving along who bumps into a wall while moving right along the screen.

    You cannot just check the coordinate (20, 0) for a collision, because the collision could occur at (20, 24)...at the bottom of the guy....but you cant check just (20, 25), because the collision could occur at (20, 0), and you cannot just check (20, 13) (the middle right) because the collision could occur above or below that....

    That means that you must check every coordinate of (20, x)...where "x" is greater than 0 and less than 25.....

    That means you must make 25 comparisons every time the guy moves right or left.....which could be happening very often....doesnt that seem a bit taxing on the computer to make 25 comparisons every time the guy moves right or left.

    Lets say you move to the right for 1 second...which is very likely and very possible....and lets say you are getting 50 fps...that means you must do 50x25 comparisons....which is 1250 comparisons in just 1 second of moving to the right....not to mention having to do all the other stuff like blitting graphics, etc...

    How much do you think that would tax the game? Is there a better way to do the collision detection then that? I'd like any input I can get....thanx...
    My Website

    "Circular logic is good because it is."

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    403

    rectangle test??

    i think you could just use a simple rectangle test.. read this article
    http://www.gamedev.net/reference/art...article754.asp

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    132
    Since you are using (I assume) 2d bitmaps, then another simple solution could be for your to determine the center co-ords of your character that is being moved. Then have a struct (or perhaps just ints if that will suffice for you) that holds the fartherest right (how many pixels towards the character's right) it's own body goes out. This isn't including the entire bitmap size, just the body. So say your using the 20x25 character, but the character itself could be boxed within 18x20 pixels. And say the middle of bitmap could be at the 10th-x-pixel and the 12th-y-pixel. This means that you could perhaps have a 9 left-x value and a 9 right-x value (or something similar... these are just quick values for the example). And the left-y value could be 10 and the right-y value could be 10 as well.

    So if the character is moving right, check the middle x co-ord of your character + 9 versus objects in your character's path. If an object is less then this value (the objects x co-ord) and higher then your character's middle x co-ord minus 9 then stop the character from going any further towards the right. Or you could go a little further and do some more checks now that you know that the object is within this area and check to see if the object is touching your character YET, cause in reality it might not be. Or you could use the first method and just stop the character where it is.

    And you could use this type of checking for if they move up or down. Its a simple method, and a lot less checking has to be done.

Popular pages Recent additions subscribe to a feed

Similar Threads

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21