ios - Rotate SCNNode to face point -
i'm trying rotate object (scnnode) face point it's moving. move across x , y axis, far tried:
// action move node let action1 = scnaction.moveto(scnvector3(x: 4.0, y: 0.0, z: 6.0), duration: 3) // tan angle: 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 target points not all.
i try add constraints array scnlookatconstraint, rotates node perfectly, stop move 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 me out wit this, please?
the easiest solution, though perhaps not elegant, apply moveto
scnaction
node, , apply scnlookatconstraint
child of node. should enable both operate without conflict.
Comments
Post a Comment