gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Fast collision detection using bounding boxes?

#6786 - cappeca - Mon Jun 02, 2003 8:10 pm

Hi,

I'm doing a fight game on the GBA, and now I have to implement colision detection during combat. I'm going with the MUGEN approach here, so my player sprite will have a "box" for attack and 4 "boxes" of hit, meaning that whenever the vertices of the attack box of one player intersects with any of the hit boxes of the other player, there's a hit.

So I have the structures like this (pseudocode):
Code:

struct collision_box [5]
{
   struct pointA
   {
       x;
       y;
   };
   struct pointB
   {
       x;
       y;
   }
}


which are updated according to the player's current state.

My questions is: what is the fastest way to calculate an intersection between the points of one box against the four others? Do I test all "x" points then "y" points, should I go testing each at a time, or is there any way I could do an OR/AND/XOR comparision? Or is this a very wrong approach in first place?

Thanks for any help.

Cesar.

#7076 - Eats - Sun Jun 08, 2003 10:57 am

look at solution 3 here:

http://astronomy.swin.edu.au/~pbourke/geometry/insidepoly/

#7078 - Lupin - Sun Jun 08, 2003 5:59 pm

How do you save wich tile is solid and wich is not when working with tile layers?

#7166 - cappeca - Wed Jun 11, 2003 5:10 am

!!!
Thanks! :-)

#7181 - Lupin - Wed Jun 11, 2003 5:38 pm

if all your boxes have an quadratic shape you could also just use an if check to check if an point or another box is within the box

#7267 - cappeca - Fri Jun 13, 2003 2:08 pm

Lupin wrote:
if all your boxes have an quadratic shape you could also just use an if check to check if an point or another box is within the box


That was my idea at first. I wanted to know what is the fastest way to do it. Considering my boxes have ABCD vertices, I just keep record of A(x,y) and C(x,y), up-left and down-right vertices. Then there's a lot of *ifs* going on to check points being inside boxes and causing colision - and I wanted to get rid of them.

That link posted by Eats gave me a lot to study, so if I come up with a better solution (for the colision problem as a whole), I'll post here. At first glance, it seems better to have a big unique polygon than 4 or 5 separate boxes, but I'll have to test it.

Cesar