【问题标题】:SceneKit isResting property on SCNPhysicsBody always returns falseSCNPhysicsBody 上的 SceneKit isResting 属性始终返回 false
【发布时间】: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


    【解决方案1】:

    根据documentation

    此属性的默认值为 false,但如果身体没有移动且不受任何力的影响,SceneKit 的物理模拟可能会自动将其设置为 true。

    所以看来其他的力量还在影响着身体。

    您最好测量身体的.velocity (documentation) 以检查它是否在移动。

    【讨论】:

    • 是的,就是这样。我目前实际上正在使用使用速度的工作版本,但我发现这个属性 isResting 并认为我会深入了解为什么它似乎不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    相关资源
    最近更新 更多