I first use UIPinchGestureRecognizer
and applyForce to move a physisc body forward or backward. Then I use UIRotationGestureRecognizer
and SCNAction
to rotate its node. The object is moving forward and rotating, but before the rotation occurs, the object jumps back to the starting position (of the node). The position of cameraNode1.presentationNode is updating, but it is resetting when using the second gesture listener. Why?
func handlePinch(recognizer: UIPinchGestureRecognizer) {
var dz = 5 * (1 - recognizer.scale)
self.cameraNode1.physicsBody?.applyForce(SCNVector3(0, 0, dz), impulse: true)
recognizer.scale = 1
}
func handleRotate(recognizer: UIRotationGestureRecognizer) {
let rot = -recognizer.rotation
recognizer.rotation = 0
let action = SCNAction.rotateByX(0, y: rot, z: 0, duration: NSTimeInterval(0))
self.cameraNode1.runAction(action)
}
I solved it by updating the position in the renderer delegate method:
func renderer(renderer: SCNSceneRenderer, updateAtTime time: NSTimeInterval) {
self.cameraNode1.position = self.cameraNode1.presentationNode.position
self.cameraNode1.rotation = self.cameraNode1.presentationNode.rotation
}