SCNAction.rotate剪辑通过其他节点

时间:2016-08-30 17:39:14

标签: ios scenekit scnnode

我有一个节点(nodeCollection),它有一个SCNNode作为childNode,它是这样创建的:

let boxGeo = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0.0)
let node = SCNNode(geometry: boxGeo)
node.physicsBody = SCNPhysicsBody.staticBody()

我也是这样创建redbox节点:

let redBox = SCNNode()
redBox.geometry = SCNBox(width: 0.5, height: 0.5, length: 0.5, chamferRadius: 0.1)
redBox.geometry?.firstMaterial?.diffuse.contents = UIColor.redColor()
redBox.position = SCNVector3Make(0, 1, -2)
redBox.physicsBody = SCNPhysicsBody.dynamicBody()

然后我运行以下代码使节点旋转

let rotateAction = SCNAction.rotateByAngle(CGFloat(M_PI_2), aroundAxis: SCNVector3Make(0, 0, 1), duration: 0.15)
rotateAction.timingMode = .EaseInEaseOut
nodeCollection.runAction(rotateAction)

然后我将nodeCollection和redBox作为childNodes添加到SCNScene

但正如您在nodeCollection上执行旋转时所看到的那样,redBox的物理特性不成立。 当红色框停止并停留在蓝框上时,物理效果会起作用

我该如何解决这个问题,以便当蓝框旋转时,它不会只剪切redBox

enter image description here

1 个答案:

答案 0 :(得分:2)

尝试将蓝色框的physicsBody类型更改为kinematic,静态实体不应移动。

这里解释了不同的类型: https://developer.apple.com/library/ios/documentation/SceneKit/Reference/SCNPhysicsBody_Class/#//apple_ref/c/tdef/SCNPhysicsBodyType