How do I organize the data structure for 2d collision?
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?
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.
[edit] of course, before checking for the actual collision, check to see if they are resonably close to eachother.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement