Using chipmunk physics - how can I tell the strength of two colliding objects

If I have two objects in a chipmunk (I am using cocos2d-iphone), once I find they collide, how can I tell how hard they are pushing against each other?

I want their strength (versus speed) to know the damage from the collision.

I saw a discussion on how to do this, but never worked with specific working code (and I couldn't get it to work, although I thought I knew what I was doing.) For completeness, here is the code I am using. to determine the collision speed, and how, in fact, will I go to the collision force detection?

- (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

+2


a source to share


1 answer


http://chipmunk-physics.net/release/Chipmunk-6.x/Chipmunk-6.0.3-Docs/#CollisionCallbacks-Handlers



You can only receive a collision impulse inside callback after answering.

+2


a source







All Articles