Reputation: 416
I'm creating a light which is a spotlight which I want to follow the person (also an SCNNode
) I want the light to be directly above the person so that the scene is dark and only visible from the small spot light above the person, this is the code for the light -
let light = SCNNode()
light.light = SCNLight()
light.light?.type = SCNLightTypeSpot
light.scale = SCNVector3Make(1, 1, 1)
light.position = SCNVector3Make(0.076, 3.715, -0.058)
light.eulerAngles = SCNVector3Make(-90, 2.578, -2.238)
let constraint2 = SCNLookAtConstraint(target: person)
constraint2.gimbalLockEnabled = true
light.constraints = [constraint2]
scene.rootNode.addChildNode(light)
so it works at the start, but when the game starts, the light seems to be getting further away and filling the whole scene which is not what I want, I want it to constantly be directly above the person at all times instead of getting bigger and filling the whole scene, can anyone help? Thanks
This is in swift
Upvotes: 1
Views: 1268
Reputation: 1196
Attach your light node to the person node instead of the root node. If your person node rotates, then put the person node in a container node that doesn't rotate and also make your light a child of that. Use the container node for translation (of both person and light), use the person node if you need to rotate the person (taking a bow, say).
Upvotes: 2