Quote:Original post by starfleetrp
Ok well then that could be computationally difficult since i'd have 128 sprites(players, of course these objects would be complex but you dont have to check inside of the main AABB unless they colide) but i'd also have around 1280 projectiles at a time (say an average of 10 per player sometime more and less. These are all visible and may live for seconds at a time). So id have to check for a collision between 128 ships and 1280 shells so that would be (128 * 1280) * (128 *1280) or arround 2 million calculations a frame, right?
However what if I only need to check for a collision between the sprites and the land, and the shells and the ships instead of checking each object with all of the others. However I am not sure exactly how I could tell the difference between a sprite and a projectile, quickly. Would I want to have a list of pointers to all of the projectiles and ships to keep them seperate so it would be more like:
for each projectile, check a collision against each sprite and
for each sprite check collision again land
NOTE: sprites do not collide
However I can see a major problem with this solution. An projectile could be deleted from the node but it would still be in the list of projectiles. Would this be the best way to do what I want, if so i'd have to find a way to work out this bug! Is there even a better way?
This is how we did it in Rumble Box:
The world is split into a grid (for simplicity sake, we'll say its 2D and it's a 2x2 grid). Each grid square has an index/iterator/pointer to an object. When an object enters a grid square, it tells the square "add me to your list", and it tells its previous grid square "remove me from your list". When an object is deleted, it tells the list "remove me from your list".
So that creates a bunch of sectors, each sector has a list of objects in it, and each object knows what sector it is in. Choosing collision possibilities are now as simple as searching nearby sectors. And you don't have the problem of "I deleted it, but it still thinks it exists" because the object just tells its own sector that it no longer exists.
I prefer to implement a system like this using a set of pre-allocated vectors for the grid, and each object has a bool to say whether it is actually valid or not. Then when we add a new object we just search for the next open slot and fill it, and when we delete it we set that bool to false. But that's just me. :)