0
votes

I am using ARKit - Scenekit to create a AR based app. I am able to successfully place the 3D model. On user tap i am trying to rotate a particular node by -120 degrees using rotateTo method. This should ideally cause smooth rotate animation. But instead the node spins around the object really fast and finally ends at -120 degrees. When i try to do the same directly in scene editor by drag-dropping rotateto action it works just fine. Only when i try to do this programmatically, it starts spinning really fast and i am not even able to preview the rotation.

Below is the code i am using to rotate the node,

 let rotateAction =  SCNAction.rotateTo(x: 0, y: 0, z: -120, duration: 2)
 self.virtualObjectManager.lastUsedObject?.childNodes[0].childNodes[0].childNodes[0].runAction(rotateAction, completionHandler: {
            })

Initial angle of the node is (0,0,0). I am trying to change it to (0,0,-120). Any one please let me know what is the issue here?

1

1 Answers

2
votes

The scenekit editor uses degrees, but SCNAction.rotateTo expects the angle in radians.

let angle = CGFloat(-120.0 * .pi / 180)
let rotateAction =  SCNAction.rotateTo(x: 0, y: 0, z: angle, duration: 2)