Jump to content
  • Advertisement
Sign in to follow this  
soarsky

How do I organize the data structure for 2d collision?

This topic is 5039 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

For example, the size of my game map is 1024*1024 pixels. I divided the map into small tiles of 32*32 pixels. And one of my units is 32*48, bigger than one tile. While one unit is smaller, 16*16. In my plan, I am going to set an array[1024,1024] related to the map size to store the occupied information. For example, the corresponding 32*48 pixels where the bigger unit stay all set to 1, and the same as the smaller all set to 2. So I can look up the occupied array to check if the units collide. I don't know if my algorithm is right and simple?

Share this post


Link to post
Share on other sites
Advertisement
Assuming that your units are rectangular, and you don't have a LOT of units, you can just put their positions/type into an array, and just check every few frames if their rectangles happen to colide.
[edit] of course, before checking for the actual collision, check to see if they are resonably close to eachother.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!