I am trying to rotate my object (SCNNode) to see the point at which it is moving. I am only moving along the x and y axis, so far I tried:
let action1 = SCNAction.moveTo(SCNVector3(x: 4.0, y: 0.0, z: 6.0), duration: 3)
let angle = CGFloat(atan2(z, x))
if angle - previousAngle > Pi {
playerAngle += 2 * Pi
} else if previousAngle - angle > Pi {
playerAngle -= 2 * Pi
}
previousAngle = angle
playerAngle = angle * RotationBlendFactor + playerAngle * (1 - RotationBlendFactor)
let rot = playerAngle - 90 * DegreesToRadians
flyNode.rotation = SCNVector4(x: 0, y: 1, z: 0, w: Float(rot))
It works for some target points, but not for all.
I am also trying to add SCNLookAtConstraint to the constraint array, it changes my node perfectly, but stops my transition to animation:
let targerNode = SCNNode()
targerNode.position = SCNVector3(x: -4.0, y: 0.0, z: -2.0)
let con = SCNLookAtConstraint(target: targerNode)
flyNode.constraints = [con]
let action1 = SCNAction.moveTo(SCNVector3(x: 4.0, y: 0.0, z: -2.0), duration: 3)
Can you help me please?
source
share