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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -