问题描述
SceneKit
当 dynamicBody
处于静止状态时,有没有办法得到通知?当 dynamicBody
落到地面并完全停止移动时,我想删除它 - 我认为我会有相当多的那些,所以我想使用基于事件的东西而不是遍历所有body
并检查它们的速度?
SceneKit
Is there a way to get notified when dynamicBody
is in resting State ?I want to remove dynamicBody
when it finished to fall to the ground and stopped moving completely - I presume that I will have quite large amount of those so I would like to use something event based rather than looping through all the bodies
and checking their velocities ?
推荐答案
您可以对 isResting
属性使用键值观察.请参阅 Swift 中是否提供键值观察 (KVO)?.
You could use Key-Value Observation on the isResting
property. See Is key-value observation (KVO) available in Swift?.
或者您可以使用 SCNPhysicsContact
和 SCNPhysicsContactDelegate
来检测与地板的碰撞,并使用它来触发速度检查.
Or you could use the SCNPhysicsContact
and SCNPhysicsContactDelegate
to detect collisions with the floor, and use that to trigger a check for velocity.
这篇关于SceneKit SCNPhysicsBody 得到休息通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!