linearGravityField()不影响场景SceneKit中的物理实体 [英] linearGravityField() is not affecting physics bodies in the scene SceneKit

查看:162
本文介绍了linearGravityField()不影响场景SceneKit中的物理实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SCNPhysicsField.linearGravityField对象来仅影响场景中的特定对象。问题是,我似乎无法让它影响任何事情。以下是我在Swift中的代码示例:

I'm trying to use a SCNPhysicsField.linearGravityField object to affect only specific objects in my scene. The problem is, that I can't seem to get it to affect anything. Here's a sample of my code in 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)

Even虽然物理实体被分配了与重力场相同的catagoryBitMask,它们只是在零G中浮动,只受物理世界引力的影响。

Even though the Physics Bodies are assigned the same catagoryBitMask as the gravity field, they just float there in zero G, only affected by the physicsworld gravity.

推荐答案

在节点上设置downGravityCatagory位掩码:

Set the "downGravityCatagory" bit mask on the node:

dice.categoryBitMask = downGravityCatagory;

物理的categoryBitMask仅用于物理碰撞。

the physics's categoryBitMask is for physics collisions only.

这篇关于linearGravityField()不影响场景SceneKit中的物理实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆