SCNLookAtConstraint(target: SCNNode) : Why does my camera ignore its target node ?

Hi, just fresh beginner with sceneKit, I got a problem I can't understand nor work around ...

the idea: a lunar module "Eagle" landing on the Moon. A camera and a spotlight are supposed to track it. All nodes have been created in a scene with the scene editor and/or directly coded from SCN routines.

the code:

camera = sceneView.scene!.rootNode.childNodes.filter({ $0.name == "theCamera" }).first! //-> got it

theEagle = sceneView.scene!.rootNode.childNodes.filter({ $0.name == "Eagle2" }).first! //- got it too

spotLight = sceneView.scene!.rootNode.childNodes.filter({ $0.name == "theSpotLight" }).first! // done.

... then the constraints:

let cameraLookAtTheEagle = SCNLookAtConstraint(target: theEagle) let spotLookAtTheEagle = SCNLookAtConstraint(target: theEagle) let cameraLookAtTheEagle.isGimbalLockEnabled = true let spotLookAtTheEagle.isGimbalLockEnabled = true let camera.constraints    = [cameraLookAtTheEagle] let spotLight.constraints = [spotLookAtTheEagle] ...

The problem is: when my Eagle starts moving up and down, it is perfectly tracked by the spot, but ignored by the camera ... and of course gets quickly out of the field.

  • I tried to use one only constraint for both of them: same result
  • I tried to implement the constraints with the scene editor: same result
  • I tried to implement the camera and the spot directly in the code: same result
  • tried to set the isGimbalLockEnabled = false: same result
  • I even try to change the order of the actions on spot and camera ... same result

Whatever I tried, the camera refuses to move a inch ...

So where's the problem ? Why does the spot always do the job, and why doesn't the camera do it?

Any advice or clue will be welcome like fresh water in the desert ... Thanks.

OK. I guess I got it ... The option:

sceneView.allowsCameraControl = true

(which allows the control of the camera by the user) is definitively incompatible with the camera tracking through the "Look At" constraint (which makes sense).

Setting the option to false solves the issue.

SCNLookAtConstraint(target: SCNNode) : Why does my camera ignore its target node ?
 
 
Q