Right now I’m doing collision entirely grid-based, and naturally that presents the occasional problem. Basically, the center of an entity is considered its location in the grid, and only one entity can exist per grid space. This mostly works, but it allows entities to pretty much overlap a lot of the time.
I decided to go with a more conventional radial/bounding-box collision check, but one implementation detail I’m wondering about is buckets.
If I were to just brute force compare every object against every other, that would be mighty slow. What I’d like to do instead is allow more than one object to exist per grid space, and have an object added multiple times (once for each vertex on its bounding box). When performing a collision check, I will therefore only check against objects that have a vertex in the same grid space.
The question here is how can I efficiently create a data structure to store a grid that can have multiple objects in it? I’m very limited on resources, so I don’t just want to make a 3D array or 2D array of lists. I’d some sort of smarter option.
My thoughts were to perhaps have a 2D array of lists (so not too much memory if it’s all null), and adaptively erase or create lists as each bucket is used. To put it in perspective, I probably will have somewhere around a 15x15 array representing the level, and only about 10 entities moving around at the most. So, maintaining 15x15 lists all the time is pretty wasteful. However, I call collision checks pretty frequently (and also test possible collisions that haven’t yet happened), so doing a brute force check or even a cached brute force check doesn’t really make sense.
So, any ideas?