I’m using Cocos2D and Box2D for a game with some physics. There’s an occasional problem where my “ball/bullet/destroyer” object gets stuck between two “target” objects and takes forever to work its way out.
This is silly because a collision between the bullet and the target object should destroy the target. (Normally, of course, this works fine.)
It hasn’t gone to sleep as in this question, because it’s vibrating around like crazy in the tiny little space between the two objects.
I have the bullet as a “bullet” object in Box2D.
Is there some minimum distance that the objects have to be in a previous frame in order to count as a collision?
The trick was that for a given “cluster” of contacts, the Box2D contact listener calls (in this order):
I was, by default, only getting contacts from
EndContact()which meant that a series of fast collisions would all happen before their effects were evaluated. I moved mydestroy-type code intoPostSolve()and all was well.