ARKit make an SCNLight point ahead where the camera is looking?

Viewed 1282

So I have access to the sceneView.pointOfViewand I want to make the AR experience feel like I am shining a flash light straight in front of my to objects I look at become lit as I point at them.

I tried to create a spotlight like this:

let spotLight = SCNLight()
spotLight.type = .spot
spotLight.spotInnerAngle = 60
spotLight.spotOuterAngle = 60
let spotNode = SCNNode()
spotNode.light = spotLight
spotNode.position = position

I then thought that adding the light to the pointOfView node would make it so the light would move with the camera, meaning it would always shine light ahead...

sceneView.pointOfView?.addChildNode(spotLight)

this is not working, the objects appear black, no light.

What am I doing wrong? I want to make it so the light points at what I look at through the AR experience, just as if I was holding a flashlight and I was shining light straight ahead....

Any suggestion?

1 Answers
Related