Speedy 2D Collision Detection

Started by
2 comments, last by Rappler 23 years, 10 months ago
I''m trying to detect collisions between an indefinate number of entities within my world''s space. Is there a faster way to detect collisions than sectorizing the game world and testing for collisions in each individual sector? Say if the world is 6400x6400 pixels and I break it into 320x320 sectors and keep track of the entities in each sector and test them against each other. There''s gotta be a better way than this, but the methods escape me right now... "The Gates of Pearl have turned to gold, it seems you've lost your way."
"The Gates of Pearl have turned to gold, it seems you've lost your way."
Advertisement
I''m not an expert but you should limit it to certain sectors rather than the whole world space (which would probably take alot of time)... and then also if you''re using loops find a way to limit down the collisions by making sure you only tested the object once... like in a loop you''d check sprite1 with sprite2 and then eventually it would get to doing sprite2 with sprite1, so you have to find a way to mark which collisions have already been tested... anyways i hope this gives ya some ideas...

-Keith Weatherby II
Also known as Uhfgood
uhfgood@artoo.net

*************************************Keith Weatherby IIhttp://twitter.com/Uhfgoodhttp://www.facebook.com/Uhfgoodhttp://www.youtube.com/Uhfgoodhttp://www.gamesafoot.comhttp://indieflux.com*************************************
another thing you might want to notice is this: if you do the sector thing, you need to watch out for instances like this:
+----+-----+
/1 3/4 6/
/ 2 / 5 /
+----+-----+
you can see that obj''s 2 and 3 are colliding, and so are 5 & 6.
but what about 3 & 4? if you simply check collisions inside each sector, you won''t catch ALL of them, cuz some will be collisions on the insides of two different sectors, like 3 & 4, they are colliding, but they aren''t in the same sector, so you won''t test them against each other.
farmersckn

Sometimes even chickens need to eat... Don't bang your head against a wall just to enjoy the good feeling when you stop.
Yesterday is the past, tomorrow is the future. Today is a gift, that is why we call it the present.
Bust it up into a &ltself censored> load of little sectors;
check for collision in the current & the 8 adject sectors (assuming you use rectangles)

just an idea, i havent done much cd yet
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement