I may have a problem imagining the best solution for a collision detection related problem. I’m writing a 2D top-down game in Java with many objects that could collide. I am planning to use the approach to create a multi resolution map, with specific objects in specific resolutions of map squares, so that I can go around the O(n²) problem and narrow down the objects in an area that could be colliding.
I have to keep a list of all objects that are residing in each map square. However, since many or sometimes all objects are moving, I have to keep these lists updated all the time.
I guess using every render cycle of an object to update the map square lists will be quite resource consuming and will probably destroy the advantage I gained by using multi resolution maps to narrow down the number objects that could be colliding with another object.
My question is now, how to keep track of all objects and filling them into the according map squares? Is there an easy way, or should I maybe choose another concept for the collision detection?
I might have forgotte some details, if there is some more information I should provide, please reply.
Thanks in advance
Best regards
i assume that you have non moving objects and moving objects. the static objects needs to register themselves only once in the multi resolution map. the moving objects have only to check if they belong now to another square if they really moved.
depending on how you do the actual collision detection you only need to recheck if the moving objects traveled a certain distance. that is the case when you check collisions with an object in the current and all surrounding squares.
the squares far away from the players square usually also don’t need to be checked every single physics pass. there is usually no action going on anyway.