将简单物理应用于SceneKit XCODE SWIFT中的.scn对象

嘿下面我有一个正常的球体,我只是为了testing我的游戏场景/世界是否有物理。 所以我只是把球放在场景/世界里,这是完美的。 它受重力的影响。 所以然后我试着做同样的事情.scn文件。 我给它的物理相同的testing球落下做对重力。 但男人不动 重力设置为-9.8来模拟正则重力代码:

//----Test-Circle-here-------------------- var sphere1: SCNNode! let sphereGeometry = SCNSphere(radius: 10.5) let sphereMaterial = SCNMaterial() let collisionCapsuleRadius = CGFloat(0.4 - 0.4) * 0.4 let collisionCapsuleHeight = CGFloat(0.4 - 0.4) sphereMaterial.diffuse.contents = UIColor.greenColor() sphereGeometry.materials = [sphereMaterial] sphere1 = SCNNode(geometry: sphereGeometry) sphere1.position = SCNVector3(x: 1.0, y: 0.05, z: 0.05) //----Giving it a physics--------- sphere1.physicsBody?.affectedByGravity = true sphere1.physicsBody?.friction = 0 sphere1.physicsBody?.restitution = 1 //bounceness of the object sphere1.physicsBody?.angularDamping = 1 // rotationess sphere1.physicsBody = SCNPhysicsBody(type: .Dynamic, shape:SCNPhysicsShape(geometry: SCNCapsule(capRadius: collisionCapsuleRadius, height: collisionCapsuleHeight), options:nil)) scnView.scene!.rootNode.addChildNode(sphere1) 

男人下面不pipe怎么样都在同一个地方

  class Character { let node = SCNNode() init() { let GuyScene = SCNScene(named: "art.scnassets/FoxMan2.scn") let characterTopLevelNode: SCNNode = GuyScene!.rootNode.childNodeWithName("Guy", recursively: true)! let collisionCapsuleRadius = CGFloat(0.4 - 0.4) * 0.4 let collisionCapsuleHeight = CGFloat(0.4 - 0.4) characterTopLevelNode.position = SCNVector3(x: 10.0, y: 0.0, z: 0.0) //----Giveing it a physics--------- characterTopLevelNode.physicsBody?.affectedByGravity = true characterTopLevelNode.physicsBody?.friction = 0 characterTopLevelNode.physicsBody?.restitution = 1 //bounceness of the object characterTopLevelNode.physicsBody?.angularDamping = 1 // rotationess characterTopLevelNode.physicsBody = SCNPhysicsBody(type: .Dynamic, shape:SCNPhysicsShape(geometry: SCNCapsule(capRadius: collisionCapsuleRadius, height: collisionCapsuleHeight), options:nil)) node.addChildNode(characterTopLevelNode) } } 

在这里input图像描述

在这里input图像描述

检查以确保您的characterTopLevelNode实际上是您认为它的节点(名称不匹配很常见)。 这常常是这种情况下的问题。 您似乎将characterTopLevelNode添加为node的子node但从不将node添加为正在显示的场景的子node

还有一件事,在创build物理体之前,不要在物理体上设置选项。

例如: sphere1.physicsBody = SCNPhysicsBody(type: .Dynamic, ... sphere1.physicsBody.affectedByGravity = true sphere1.physicsBody.friction = 0 sphere1.physicsBody.restitution = 1 sphere1.physicsBody.angularDamping = 1