How can I get the current velocity of a SCNPhyisicsBody?
The velocity property does always return (0.0, 0.0, 0.0), and the physicsBody of the prensetationNode of my SCNNode is also nil.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With