2

I am using this function to animate a rotation of a SCNNode:

   let rotateNode = SCNAction.rotateTo(x: 0.0, y: CGFloat((headingAngle )), z: 0.0, duration: TimeInterval(1.1), usesShortestUnitArc: true)


    node.runAction(rotateNode)

It works really well for different directions except for when I need to rotate it towards the user (or the camera for that matter).

My question is how to direct the SCNNode to move towards the user/camera and how to calculate the headingAngle in order to rotate the SCNNode to face the user/camera when it is moving.

I perform the moving by using

           let impulseVector = SCNVector3(
            x: 0.0 ,
            y: 5.0,
            z: 0.0
        )

    node.physicsBody?.applyForce(impulseVector, at: positionOnNodeToApplyForceTo, asImpulse: true) // propell

And I am aware that the headingAngle needs to be calculated using atan2 function, but for some reason I do not manage to properly direct the SCNNode to move towards the camera nor to rotate and face the camera.

Tim Friedland
  • 1,045
  • 11
  • 18

0 Answers0