SceneKit : SCNPhysicsBody get current velocity

前提是你 提交于 2019-12-05 08:24:04

You can get the "current" velocity with

physicsBody.velocity

But this is valid only within the "game loop" callbacks (updateAtTime, didApplyAnimations, didSimulatePhysics, will/didRenderScene).

...in your view controller, you have to use SCNSceneRendererDelegate protocol like

class GameViewController: UIViewController,SCNSceneRendererDelegate{...

and in the viewDidLoad method set the SCNView delegate to scnView.delegate=self

Then you can implement for example

func renderer(renderer: SCNSceneRenderer, didRenderScene scene: SCNScene, atTime time: NSTimeInterval) {

    let scnView = self.view as! SCNView
    let scene = scnView.scene
    let compass = scene?.rootNode.childNodeWithName("ObjectName", recursively: true)

    print((compass?.physicsBody?.angularVelocity)!)
}

this works in my case. hope it helps a bit!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!