Using Chipmunk physics - how can I tell the force of two colliding objects
If I have two objects in chipmunk (I'm using cocos2d-iphone), once I've detected that they collided, how can开发者_如何学运维 I tell how hard they are hitting each other?
I want their force (vs. the velocity) to know the damage of the collision.
I've seen discussion about how to do this, but never concrete working code (and I couldn't get it work, even though I thought I knew what I was doing.) For completeness, here is the code that I am using to determine the Velocity of the collision, so, how, precisely, would I go about detecting the Force of a collision?
- (BOOL) handleCollisionBetweenBalls:(CollisionMoment)moment arbiter:(cpArbiter*)arb space:(cpSpace*)space {
JjrFootprint(@"handleCollisionBetweenBalls");
if (moment == COLLISION_BEGIN) {
JjrLog(@"Balls Collide");
CP_ARBITER_GET_SHAPES(arb, a, b);
cpVect va;
cpVect vb;
va = a->body->v;
vb = b->body->v;
cpVect vNet = cpvadd(va,vb);
cpFloat Length = cpvlength(vNet);
// 7 = barely touching
// 1000 = hard
if (Length > 100) {
[[SimpleAudioEngine sharedEngine] playEffect:@"board.wav"];
}
}
return YES;
}
Thanks, JJ
http://chipmunk-physics.net/release/Chipmunk-6.x/Chipmunk-6.0.3-Docs/#CollisionCallbacks-Handlers
You can only get the collision impulse from inside the post solve callback.
精彩评论