Light not moving with Camera - SceneKit

Viewed 209

My light doesn't follow my camera.

I've added the light as a childNode of the camera before adding the camera to the scene, and this still doesn't fix the problem.

    override func viewDidLoad()
    {
        super.viewDidLoad()

        let scene = SCNScene()

        let shipScene = SCNScene(named: "merchant.scn")

        guard let shipNode = shipScene?.rootNode.childNode(withName: "merchant", recursively: true)
        else
        {
            fatalError("ShipModel is not found!")
        }

        shipNode.position = SCNVector3(x:0, y:0, z:0)

        scene.rootNode.addChildNode(shipNode)


        let lightNode = SCNNode()
        lightNode.light = SCNLight()
        lightNode.light?.type = .omni
        lightNode.position = SCNVector3(x:0, y:2, z:10)

        let cameraNode = SCNNode()
        cameraNode.camera = SCNCamera()
        cameraNode.position = SCNVector3(x:0, y:1, z:8)

        cameraNode.addChildNode(lightNode)

        scene.rootNode.addChildNode(cameraNode)


        let sceneView = self.view as! SCNView
        sceneView.scene = scene

        sceneView.showsStatistics = true
        sceneView.backgroundColor = UIColor.gray
        sceneView.allowsCameraControl = true

    }

The light, regardless of the camera's position, still only illuminates the very front of the model.

1 Answers

Perfect. only missing line is as below.

sceneView.pointOfView = cameraNode
Related