SceneKit's look(at:up:localFront:) not working right in certain scenarios

423 views Asked by At

This can be reproduced using the default Xcode 3D game template (SpaceShip).

Remove the runAction line that rotates the ship in the GameViewController.

Add this line. The ship correctly faces away from the camera. Note the very small x component in the at: parameter.

ship.look(at: SCNVector3(0.001, 0, -100.0), up: SCNVector3(0, 1, 0), localFront: SCNVector3(0, 0, 1)) // Works! Ship faces away from camera.

However, it the x component of the at: parameter is exactly zero, the ship's orientation does not change. The ship continues to face the camera instead of facing away from it.

ship.look(at: SCNVector3(0, 0, -100.0), up: SCNVector3(0, 1, 0), localFront: SCNVector3(0, 0, 1)) // DOES NOT work

Seeing the same problem with simdLook()

1

There are 1 answers

1
impression7vx On

For starters, if you show the world origin sceneView.debugOptions = ARSCNDebugOptions.showWorldOrigin], you will see that the x and y axis are actually opposite to what they would normally be, i.e. x is now y and y is now x.

Second, you are changing the x axis and not z axis. If you want the spaceship to look away or at you, that runs along the z axis. Negative(-) z will look at you where Positive(+)z will look away from you. Trying just changing the -100 to +100.