SCNPhysicsBody在SceneKit中不匹配

时间:2016-06-20 20:17:49

标签: ios swift physics scenekit

我试图阻止那个移动的人用飞机撞击但它没有停止,因为它从飞机上飞走。根据苹果文档,我将简单的形状应用于移动人的胶囊,并设置碰撞类别但它不工作。任何人请帮助我... 这是我的代码

//Following SceneKit fox example make my character shape
node = SCNNode()
characterScene = SCNScene(named: "game.scnassets/Logan.dae")!

characterNode = characterScene.rootNode.childNodeWithName("Logan", recursively: true)!
node.addChildNode(characterNode)

let (min, max) = node.boundingBox
let collisionCapsuleRadius = CGFloat(max.x - min.x) * 0.4
let collisionCapsuleHeight = CGFloat(max.y - min.y)

let characterCollisionNode = SCNNode()
characterCollisionNode.name = "Logan"
characterCollisionNode.position = SCNVector3(0.0, collisionCapsuleHeight * 0.51, 0.0) 
characterCollisionNode.physicsBody = SCNPhysicsBody(type: .Kinematic, shape:SCNPhysicsShape(geometry: SCNCapsule(capRadius: collisionCapsuleRadius, height: collisionCapsuleHeight), options:nil))
characterCollisionNode.physicsBody!.contactTestBitMask = collisionHero | collsionTarget
node.addChildNode(characterCollisionNode)

以下是飞机的代码:

let plane = SCNPlane(width:20.0,height:20.0)
var planeNode = SCNNode(geometry: plane)
planeNode.position = SCNVector3(4.0,0.0,-5.0)
planeNode.physicsBody = SCNPhysicsBody.staticBody()
planeNode.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Static,
                                      shape: SCNPhysicsShape(geometry: plane, options: nil))

characterNode.physicsBody?.contactTestBitMask = collisionHero | collsionTarget
characterNode.physicsBody?.categoryBitMask = collisionHero
characterNode.physicsBody?.collisionBitMask = collsionTarget
planeNode.physicsBody?.contactTestBitMask =   collsionTarget
planeNode.physicsBody?.categoryBitMask = collsionTarget
planeNode.physicsBody?.collisionBitMask = collisionHero

有人可以指出我代码中的错误在哪里吗?

感谢。

0 个答案:

没有答案