I have a peculiar problem that I've been trying to fix for the last 2 days (20 hours total), and I am stumped!
Here is the problem: one of my separate collision handler is being called twice and I cant figure out why. It is called when the object is in a mid-way collision with another object, and once more when it actually separates. I read that when the object is being removed, the separation handler gets called again but the objects are not being removed. The odd thing is, the collision handler is only called twice when the object is at an positive rotation angle! When it has a negative rotation angle it works fine.
Here is the code snippet for the object:
Code: Select all
...
cpVect square[] = {cpv(-boundaries.width/2,0), cpv(-boundaries.width/2,40), cpv(boundaries.width/2,40), cpv(boundaries.width/2,0)};
HoverShape = cpPolyShapeNew(GameBody, 4, square, cpv(0,boundaries.height/2));
HoverShape->sensor = true;
HoverShape->collision_type = HoverCollision;
HoverShape->data = self;
cpSpaceAddShape(GameSpace, HoverShape);
cpSpaceAddCollisionHandler(GameSpace, HoverCollision, CollisionScreenBorder, checkSeparated, NULL, NULL, Separated, NULL);
..
Code: Select all
GroundBody = cpBodyNewStatic();
float radius = 10.0f;
cpShape *groundShape = cpSegmentShapeNew(GroundBody, lowerLeft, lowerRight, radius);
groundShape->e = 1.0f;
groundShape->sensor = true;
groundShape->u = 1.0f;
groundShape->collision_type = bCollisionScreenBorder;
groundShape->layers ^= GRABABLE_MASK_BIT;
cpSpaceAddShape(GameSpace, groundShape);
Code: Select all
static void Separated(cpArbiter *arb, cpSpace *space, void *unused){
cpShape *hover, *border;
cpArbiterGetShapes(arb, &hover, &border);
HoverObj* obj = (HoverObj*)hover->data;
CCLOG(@"called");
}
Edit
It seems to call the begin collision handler twice too, so it may have ended the collision event and started another one instantaneously?