Skip to main content
7 of 8
deleted 21 characters in body

How to handle objects at the edges of spatial partition cells?

I've started writing code for collision detection in a 2D game, and common methods I've seen include gridding and quadtrees. I also plan to use them for nearest neighbour searches, etc.


I see most games store object positions as floats and have a closed ball for the game area (eg. a rectangle and objects are allowed to have position coordinates on all 4 edges).

However, this becomes problematic when dividing the game area up (for both gridding/quadtrees). You'll either have to include edge cases in your code so that 2 edges of the game area are included in rectangles that touch them or you miss out 2 edges in collision detection (in which case objects on those edges won't be in the grid/tree).


I haven't seen this sort of problem mentioned in any of the articles I've read/when I search it up. So I wonder - is there another solution to this or do games usually go with one of the above 2 solutions?

(In one example I noticed object positions were integers which avoids this problem, but I'd rather keep them as floats in the game I'm making)