For collision detection only, is Chipmunk or Box2d the better tool?
For a Cocos2d based project, I'd like to use a physics toolkit for collision detection only. What are th开发者_如何学Pythone pros/cons of using Chipmunk or Box2d?
According to this answer Chipmunk does not support Continuous Collision Detection, but Box2D does. This is important to prevent "tunneling" (objects passing slightly through eachother when moving at high speeds)
This is clarified by Steffen Itterheim's comment on his Box2D vs Chipmunk FAQ: If you are going to have very fast moving physics objects, eg "Bullets", consider using Box2D as it can do swept collisions aka continuous collision integration to prevent fast-moving objects from deeply penetrating or even tunneling through other objects.
The Chipmunk Collision Detection docs talk about a separate()
callback. Two shapes have just stopped touching for the first time this step. but it was unclear to me if this has any implications of their ability to detect collisions at speed.
There is also a very negative opinion on using Box2D for a breakout game My current game is using Box2D, and I wish I used Chipmunk with it... Mostly because Box2D has two serious issues, that are exacerbated on my game: First, it has a REALLY OLD bug where objects "snag" on corners, my game is a breakout game, so when the ball is "rolling" along a wall, sometimes it snag and is flung away from the wall, lots of people asked why my game physics looks "random".
Conclusion: I'm confused too.
What kind of collisions are we talking about?
If all you need are these:
- rect intersects rect -> CGRectIntersectsRect(..)
- point in rect -> CGRectContainsPoint(..)
- radius intersect (ie distance of two points) -> ccpDistance(..)
Then you don't need a physics engine at all, and you don't have to write your own collision detection algorithms either.
Chipmunk and Box2D handle collisions equally well. I'm of the opinion that if one is asking "which is better" it's not going to matter for you. Instead, ask yourself whether you're more comfortable working with C (Chipmunk) or C++ (Box2D).
Similarly, do you prefer working with an object-oriented, verbose API (Box2D) or a functional, highly abbreviated API (Chipmunk)?
Base your decision on what makes it easier for you to work with rather than some arbitrary, undefined, and highly subjective idea of whether one physics engine might be better than the other, because the technical differences are marginal and you can only assess their influence on your game's design if you both know your own game design and the physics engines internal algorithms really well.
精彩评论