在SceneKit中不受重力场影响的对象

时间:2015-07-23 18:25:17

标签: ios swift game-physics scenekit

我使用SceneKit进行骰子的3d物理模拟。我试图只使用SCNPhysicsField.linearGravityField()来影响特定的骰子。我认为我已经拥有了所有必要的代码,但它只是不起作用。物理实体不受重力场的影响,即使它在默认情况下是无限的,并且它们属于同一类别。我使用swift。

let downGravityCatagory = 1 << 0
let fieldDown = SCNPhysicsField.linearGravityField()
let fieldUp = SCNPhysicsField.linearGravityField()
let fieldNode = SCNNode()

let sceneView = view as! SCNView
sceneView.scene = scene
sceneView.scene!.physicsWorld.gravity = SCNVector3(x: 0, y: 0, z: 0)

fieldDown.categoryBitMask = downGravityCatagory
fieldDown.active = true
fieldDown.strength = 3
fieldNode.physicsField = fieldDown
scene.rootNode.addChildNode(fieldNode)

var dice = SCNNode()
//I then attach geometry here
dice.physicsBody = SCNPhysicsBody(type: SCNPhysicsBodyType.Dynamic, shape: SCNPhysicsShape(geometry: dice.geometry!, options: nil))
dice.physicsBody?.categoryBitMask = downGravityCatagory
scene.rootNode.addChildNode(dice)

这个问题是我存在的祸根。据我所知,这是代码应该如何编写。据我所知,这项工作所需的所有先决条件都已得到满足。

0 个答案:

没有答案