I am trying to build some project using SCNPhysicsContactDelegate, but it I found that it detects contact between my nodes too early. I need it to be 100% precise and correct. I am attaching screenshot of too early contact detection. There is my code for theirs physics bodies:
nodeA code:
nodeA = SCNNode(geometry: SCNBox(width: 0.3, height: 0.3, length: 0.3, chamferRadius: 0.05))
nodeA.position = SCNVector3(0, 3.3, 0)
nodeA.geometry?.firstMaterial?.diffuse.contents = UIColor.red
nodeA.physicsBody = SCNPhysicsBody.dynamic()
nodeA.physicsBody?.physicsShape = SCNPhysicsShape(node: nodeA, options: nil)
nodeA.physicsBody?.categoryBitMask = PhysicsCategories.nodeA
nodeA.physicsBody?.contactTestBitMask = PhysicsCategories.nodeB
nodeA.physicsBody?.isAffectedByGravity = false
nodeA.name = "nodeA"
nodeA.opacity = 0
self.scene.rootNode.addChildNode(self.nodeA)
nodeB code: (nodeB already exists, so I am only adding physics body)
nodeB.physicsBody = SCNPhysicsBody.kinematic()
nodeB.physicsBody?.physicsShape = SCNPhysicsShape(node: nodeB, options: nil)
nodeB.physicsBody?.categoryBitMask = PhysicsCategories.nodeB
nodeB.physicsBody?.contactTestBitMask = PhysicsCategories.nodeA
contact function code:
func physicsWorld(_ world: SCNPhysicsWorld, didBegin contact: SCNPhysicsContact) {
scene.isPaused = true
}
Could you please someone help me find the solution? I look forward to your hearings guys.
Thanks Jakub
var stopIt = false
, then in physics world function, when the contact is triggered this code runs: stopIt = true, and then in didRenderScene method:if stopIt{ scene.isPaused = true}
But after that result looks still the same.The box is still being stopped too early – Jakub