Hacker News new | ask | show | jobs
by jiggy2011 5071 days ago
I've wanted to do a project with Box2D for a while and have a few ideas for physics heavy games. However all the ideas I have involve pretty large game worlds with many objects so I am worried about the performance of this.

I read somewhere that collision detection in Box2D is O(N^2), is the answer to write custom collision detection and simply use box2d to process the effects of these?

1 comments

I'm reasonably sure that this used to be the case but hasn't for a good while. I know at some point Box2D used a sort-and-prune algorithm but they may have moved on to quadtrees or space-filling curves by now. You could also try Chipmunk which provides several collision recipes too, and may be faster for lots of similarly-sized objects. And you can always ignore either of them for collisions and take it as a learning experience to implement different algorithms yourself.

But you really need to just make it and see. Even a naive n^2 algorithm will be fine, for small values of n. If you have a lot of objects though you might even be forced into using a 3D engine and making the GPU do some work. Once you're in the process of making your game you'll be more aware of what specific optimizations you can make (such as sprite groups).