SceneKit : SCNPhysicsBody get current velocity SceneKit : SCNPhysicsBody get current velocity xcode xcode

SceneKit : SCNPhysicsBody get current velocity


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!