In the scene, two 3d objects are not contacting with each other, but the function func physicsWorld(_ world: SCNPhysicsWorld, didBegin contact: SCNPhysicsContact) {}
is called.
I use addItem()
to add nodes in the scene
func addItem(hitTestResult: ARHitTestResult) {
if let selectedItem = self.selectedItem {
let scene = SCNScene(named: "art.scnassets/\(selectedItem).scn")
let node = (scene?.rootNode.childNode(withName: selectedItem, recursively: false))!
let transform = hitTestResult.worldTransform
let thirdColumn = transform.columns.3
node.position = SCNVector3(thirdColumn.x, thirdColumn.y, thirdColumn.z)
node.physicsBody = SCNPhysicsBody(type:.dynamic, shape: SCNPhysicsShape(node: node, options: nil))
node.physicsBody?.isAffectedByGravity = false
node.physicsBody?.categoryBitMask = BitMaskCategory(rawValue: selectedItem)!.maskValue
node.physicsBody?.contactTestBitMask = BitMaskCategory.mug.maskValue
self.sceneView.scene.rootNode.addChildNode(node)
}
}
enum BitMaskCategory: String {
case mug, banana, cup, vase
var maskValue : Int {
switch self {
case .mug: return 1
case .banana: return 2
case .cup: return 3
case .vase: return 4
}
}
}
As soon as I tap the screen and add two nodes(cup and mug) in the scene, these two nodes start to move away from each other. They are repelling each other, even though they are not contacting with each other.
Thanks.