0

This is the code I'm using:

    func didBeginContact(contact: SKPhysicsContact) {

    var firstBody  : SKPhysicsBody?
    var secondBody : SKPhysicsBody?
    var thirdBody  : SKPhysicsBody?
    var GoodKind   : SKNode?
    var BadKind    : SKNode?
    var Bullet     : SKNode?

    if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask) {
        firstBody  = contact.bodyA
        secondBody = contact.bodyB

        GoodKind   = contact.bodyB.node
        BadKind    = contact.bodyB.node
        Bullet     = contact.bodyA.node
    }
    else {
        firstBody  = contact.bodyB
        secondBody = contact.bodyA

        GoodKind   = contact.bodyA.node
        BadKind    = contact.bodyA.node
        Bullet     = contact.bodyB.node
    }

    if (firstBody!.categoryBitMask == PhysicsCategory.Tooth && secondBody!.categoryBitMask == PhysicsCategory.Food) {
        GoodKind?.removeFromParent()
        Counter++
        println("\(Counter)")
    }
    else if (firstBody!.categoryBitMask == PhysicsCategory.Tooth && secondBody!.categoryBitMask == PhysicsCategory.WrongFood) {
        BadKind?.removeFromParent()
        Bullet?.removeFromParent()
    }
}

If the Bullet collide with the BadKind then the BadKind is removed with the bullet which is fine; if the Bullet collide with the GoodKind then the GoodKind is removed and the Counter works fine, but if two or more Bullet collide with the GoodKind nearly at the same moment the Counter will increase 2 or more times. That is what I don't want to happen but I can't figure out how to make it work the way I want. I would appreciate some help.

0 Answers0