我正在尝试使用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)
即使为物理实体分配了与重力场相同的catagoryBitMask,它们也只是以零G漂浮在此处,仅受Physicalworld重力影响。
最佳答案
在节点上设置“downGravityCatagory”位掩码:
dice.categoryBitMask = downGravityCatagory;
物理的categoryBitMask仅用于物理碰撞。
关于ios - linearGravityField()不会影响场景SceneKit中的物理物体,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31577723/