我正在学习如何在ARKit中使用物理学。到目前为止,我已经创建了可以相互交互的对象,但是didBegin函数没有被调用。
我已将ViewController设置为符合SCNPhysicsContactDelegate。
class ViewController: UIViewController, ARSCNViewDelegate, SCNPhysicsContactDelegate
在viewDidLoad内部,我指定它为联系人委托:
sceneView.scene.physicsWorld.contactDelegate = self
然后我添加了此方法:
func physicsWorld(_ world: SCNPhysicsWorld, didBegin contact: SCNPhysicsContact) {
print("Contact happened!")
}
我将物理物体添加到两个对象:
mars.physicsBody = SCNPhysicsBody(type: .kinematic , shape: nil)
mars.physicsBody?.categoryBitMask = 2
mars.physicsBody?.collisionBitMask = 4
mars.physicsBody?.contactTestBitMask = 4
mars.physicsBody?.restitution = 1
和:
blueBall.physicsBody = SCNPhysicsBody(type: .dynamic, shape: nil)
blueBall.physicsBody?.categoryBitMask = 4
blueBall.physicsBody?.collisionBitMask = 2 | 4
blueBall.physicsBody?.contactTestBitMask = 2 | 4
blueBall.physicsBody?.restitution = 1
当对象碰撞时,它们会相互反弹,但不会调用print语句。
我想念什么?