gpt4 book ai didi

ios - SCNPhysicsBody 上的 SceneKit isResting 属性始终返回 false

转载 作者:行者123 更新时间:2023-11-28 23:32:38 25 4
gpt4 key购买 nike

我正在使用 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()
}
}

最佳答案

根据documentation :

This property’s default value is false, but SceneKit’s physics simulation may automatically set it to true if the body is not moving and not affected by any forces.

看来还有其他力量在影响着 body 。

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

关于ios - SCNPhysicsBody 上的 SceneKit isResting 属性始终返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55968712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com