Sign in to follow this  

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

This topic is 4732 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
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

This topic is 4732 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this