HomeiOS Developmentios - Unattainable contact in SceneKit

ios – Unattainable contact in SceneKit


The physicsWorld(_:didBegin:) operate ought to solely be referred to as when some node’s class bit is about in one other nodes contactTest bit masks. Nevertheless, in my code, there may be an not possible state of affairs occurring the place a contact is happening when neither of the contacting our bodies have one another of their contactTest bit masks. Eg:

func physicsWorld(_ world: SCNPhysicsWorld, didBegin contact: SCNPhysicsContact) {
    if (contact.nodeA.physicsBody!.categoryBitMask & contact.nodeB.physicsBody!.contactTestBitMask) != 0 {
        print("All good")
    } else if (contact.nodeA.physicsBody!.contactTestBitMask & contact.nodeB.physicsBody!.categoryBitMask) != 0 {
        print("All good")
    } else {
        fatalError("Unattainable")  // << Execution reaches right here
    }

    // .. Code dealing with the contact ...
}

I seen this began occurring once I added this line to the physicsWorld(_:didBegin:) operate:

// The ball is the one node within the recreation that has a contactTestBitMask apart from 0
let ball = contact.nodeA.title == "ball" ? contact.nodeA : contact.nodeB
ball.physicsBody!.contactTestBitMask = PhysicsCategory.dynamic

No matter what code I add to the operate, that fatalError ought to by no means be reached. I do not know if altering bit masks inside the didBeginContact methodology results in undefined behaviour, however I nonetheless do not suppose the physicsWorld(_:didBegin:) ought to ever get referred to as if categoryBitMask & contactTestBitMask == 0.

If I alter nodeA/B.physicsBody!.categoryBitMask to nodeA/B.categoryBitMask then it by no means crashes, however based on the documentation, a SCNNodes class bit masks property would not have an effect on the SceneKit physics simulation.

If anybody has any suspicious of why this might occur please let me know as I am satisfied it is a bug.

Thanks

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments