0 Replies
      Latest reply on Aug 26, 2017 1:20 AM by rex
      rex Level 1 Level 1 (0 points)

        In my ARKit app, I have a goal (`SCNTorus` hoop) that I'm shooting `SCNSphere`'s through. I need to detect when the sphere has gone from one side, through the torus, and out the other side of the torus.

         

        My current approach is using node `physicsBody.collisionBitMask`'s on both `SCNNode`s. The first node is a node that sits inside the SCNTorus as a detector/sensor node. The other nodes would be the spheres.

         

        With `SCNPhysicsContactDelegate`, I'm able to detect the various callbacks like `didEnd` https://developer.apple.com/documentation/scenekit/scnphysicscontactdelegate/1512883-physicsworld.

         

        While logging, I'm looking at the `penetrationDistance` of SCNPhysicsContact. The `penetrationDistance` is

         

        > The distance of overlap, in units of scene coordinate space, between the two physics bodies.

         

        https://developer.apple.com/documentation/scenekit/scnphysicscontact/1522870-penetrationdistance

         

            func physicsWorld(_ world: SCNPhysicsWorld, didEnd contact: SCNPhysicsContact) {
                let maskA = contact.nodeA.physicsBody?.categoryBitMask
                let maskB = contact.nodeB.physicsBody?.categoryBitMask
                let penetrationDistance = contact.penetrationDistance
            
                if (maskA == CollisionTypeOne) && (maskB == CollisionTypeTwo) {        
                    print(penetrationDistance)
                
                } else if (maskB == CollisionTypeOne) && (maskA == CollisionTypeTwo) {
                    print(penetrationDistance)
                }
            }
        

         

        What I expected was that I could compare the size/diameter of my sphere to the `penetrationDistance`. The reality is `didEnd` fires multiple times for one actual event (ball going through the hoop). The `penetrationDistance` seems too small individually to be helpful.

         

        What is the best approach to detect pass through "collision" events in SceneKit?