【发布时间】:2019-09-21 22:27:19
【问题描述】:
我正在使用ARKit/SceneKit 将球加载到ARSCNView 中,并且球沿着地板移动直到停止,具体取决于我对球施加的力。
SCNNode 具有用于检测节点何时停止移动的属性,并使用以下方法将其 isResting 属性设置为 true:
myNode.physicsBody?.isResting
我已将 myNode 的物理主体设置为注册休息使用:
myNodesPhysicsBody.allowsResting = true
我的球类中有一个函数应该检测球何时停止使用:
func removeBowlingBallWhenNotMoving() {
guard let bowlingBallNode = bowlingBallNode else {return}
guard let resting = bowlingBallNode.physicsBody?.isResting else {return} // I know I can combine these guard statements they're just here for easier debugging
print("Resting: \(resting)") // This always returns false even when the node has visually stopped moving.
if resting {
performFadeOutOnBowlingBallWith(duration: Constants.bowlingBallFadeOutDuration)
}
}
在didSimulatePhysicsAtTime中调用:
extension ViewController: ARSCNViewDelegate {
func renderer(_ renderer: SCNSceneRenderer, didSimulatePhysicsAtTime time: TimeInterval) {
bowlingBall.removeBowlingBallWhenNotMoving()
}
}
【问题讨论】:
标签: ios scenekit arkit scnnode