Chola
Chola

Reputation: 11

How to make collision in scenekit

i am trying to make collision of two objects, but "func physicsWorld(world: SCNPhysicsWorld, didBeginContact contact: SCNPhysicsContact)" is not being called.

my code is,

    let carbonNode = SCNNode(geometry: carbonAtom())
    carbonNode.position = SCNVector3Make(-6, 8, 0)        

    let coneAtomNode = SCNNode(geometry: coneAtom())
    pinNode = coneAtomNode

    pinNode.physicsBody = SCNPhysicsBody.dynamicBody()
    pinNode.physicsBody?.restitution = 0.9;
    pinNode.categoryBitMask = 0x4;
    pinNode.physicsBody?.collisionBitMask = ~(0x4);

    coneAtomNode.position = SCNVector3Make(-6, -15, 0)
    scene.rootNode.addChildNode(coneAtomNode)

    balloonNode = carbonNode

    sceneView.scene = scene
    sceneView.scene?.physicsWorld.contactDelegate = self

     pinNode.runAction(SCNAction.repeatAction(SCNAction.moveTo(SCNVector3Make(-6, 10+5, 0), duration: 1.5), count: 1), completionHandler: {

    })

Upvotes: 1

Views: 1546

Answers (1)

Toyos
Toyos

Reputation: 4064

You can't move "dynamic" bodies programmatically (i.e no action, no animation and no manual updates of position/rotation/scale). You can either move dynamic bodies with forces or use a kinematicBody instead. Kinematic bodies behave just like static bodies but you can move them programmatically.

Also if you want to get physics contacts between two nodes, the two nodes need to have a physicsBody.

Upvotes: 3

Related Questions