6

For a Cocos2d based project, I'd like to use a physics toolkit for collision detection only. What are the pros/cons of using Chipmunk or Box2d?

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Daniel Blezek
  • 4,539
  • 1
  • 19
  • 20
  • If you don't want to handle physics, why include an entire library to do it? – alex Oct 06 '11 at 12:00
  • While I don't need the physics, I would like to have an easy to use collision detection system, so I don't have to write my own. Including a toolkit shouldn't be that much of a problem. – Daniel Blezek Oct 06 '11 at 12:03
  • 3
    Quite a subjective question, the 'better' one is the one you can learn fastest and understand best. – James Webster Oct 06 '11 at 19:47
  • cocos2d 0.5rc0 claims that it adds a basic collision module. Have you looked into just using that? – Tony Adams Oct 08 '11 at 13:38
  • cocos2d 0.5 -> applies only if we're talking about cocos2d (Python) for desktop computers. – CodeSmile Oct 11 '11 at 13:15

2 Answers2

9

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.

Community
  • 1
  • 1
Andy Dent
  • 17,578
  • 6
  • 88
  • 115
5

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.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • 1
    I did this in a game recently and I wouldn't recommend it at all. Cocos2D has serious issues with overlay views like Game Center login notification or any iOS 5 system notification where your update method skips some frames, resulting in occasional "tunneling" effect that Andy described in his answer. Unless you have large objects moving slowly, you should use a physics engine with decent collision detection. In Cocos2D case it's probably best to use Box2D. – Filip Radelic Dec 21 '11 at 02:48