I know chipmunk physics pretty well. But I've run into a problem I can't solve easily. I should say I'm using chipmunk pro.
I'd like to create a planet moving through space and affected by forces. But I want it to react to collisions like a static object. So I want it to be physics simulated and apply forces to it. But once another object hits it I want it to ignore the collision (of course the other object shouldn't ignore it but bounce off it as if it was static/infinite mass).
Obviously two of these passive objects couldn't collide, but they'll be grouped together, and will never touch by design.
I've tried to do it in collision handles, but I can't really figure it out, I'm not asking for source code, I'd like a point in the right direction though
Thanks,
Theis
SOLUTION:
Code: Select all
-(BOOL) begin:(cpArbiter *)arbiter space:(ChipmunkSpace *)space {
GameSprite * objectA = ((__bridge ChipmunkBody*)arbiter->body_a_private->data).data;
GameSprite * objectB = ((__bridge ChipmunkBody*)arbiter->body_b_private->data).data;
//NSLog(@"Begin %@ %@",objectA,objectB);
if (objectA.ignoreImpacts) {
//objectA.storedVelocity = objectA.chipmunkBody.vel;
objectA.storeMass = objectA.chipmunkBody.mass;
objectA.chipmunkBody.mass = INFINITY;
objectA.storeMoment = objectA.chipmunkBody.moment;
objectA.chipmunkBody.moment = INFINITY;
}
if(objectB.ignoreImpacts) {
objectB.storeMass = objectB.chipmunkBody.mass;
objectB.chipmunkBody.mass = INFINITY;
objectB.storeMoment = objectB.chipmunkBody.moment;
objectB.chipmunkBody.moment = INFINITY;
}
return YES;
}
-(void) separate:(cpArbiter *)arbiter space:(ChipmunkSpace *)space {
//NSLog(@"Separate");
GameSprite * objectA = ((__bridge ChipmunkBody*)arbiter->body_a_private->data).data;
GameSprite * objectB = ((__bridge ChipmunkBody*)arbiter->body_b_private->data).data;
if (objectA.ignoreImpacts) {
objectA.chipmunkBody.mass = objectA.storeMass;
objectA.chipmunkBody.moment = objectA.storeMoment;
}
if (objectB.ignoreImpacts) {
objectB.chipmunkBody.mass = objectB.storeMass;
objectB.chipmunkBody.moment = objectB.storeMoment;
}
}