Collision

Jones
Unregistered
 
Post: #1
The thing I hear more experienced developpers asking about the most on web forums is collision detection. When I started my first little game project I said to myself "Well, if I can write my own collision detection system for this, then I'd already have gotten past the hardest part of simple game programming". So instead of looking for a library to do it for me, I thought hard for a minute, and two theories popped into my mind:

- A function that cross checks arrays of pixel data.
- A function that compares object position and size versus each other.

At the time I had no idea what they were each called, so I named the first one "Pixel Mapping Collision".
I now know that those two types of collision are called "Pixel Perfect Collision" and "Bounding Box Collision". Funnily enough, I chose the first one, as it just seemed clearer. My first collision header was very very slow, about 1 frame per few minutes as it compared EVERY pixel of the objects against each other. Version two seemed fast, until I realized for some reason it wasn't working at all. Wacko The idea behind said v2 was to compare ONLY the outer edges of the objects, as they would be the only ones coming in contact with each other. I'm still going through it over and over to find out why it didn't work.

But then I realised... this is gonna be infinitly hard to modify to support colorkeys, so now I'm restarting, except this version will be different from the last two. It will take each objects colorkey and then scan through the object, and will try to devide it into box sections that I can use for faster bounding box collision.

Thing is, am I on the right track? I have a feeling that v3 will be just as slow because it will need to try and "seek out" boxes...

Well, thanks for listening to my problems and plans. Rolleyes
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #2
do a bounding box test before pixel-pixel testing.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Jones
Unregistered
 
Post: #3
unknown Wrote:do a bounding box test before pixel-pixel testing.

That could speed it up, but it would just slow down again if the bounding-box test returned true, would it not?
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #4
It will be faster in general, but really i'd avoid doing pixel-pixel checks at all costs.
Instead you could try and approximate the shape with circles, bounding boxes or polygons. Pretty much anything is faster than pixel-pixel collision detection.

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 1,140
Joined: 2005.07
Post: #5
Jones Wrote:That could speed it up, but it would just slow down again if the bounding-box test returned true, would it not?
Yes, it would, but only if it return true. Since relatively few objects would return true, then it would speed it up considerably.
Quote this message in a reply
Post Reply