Answer the question
In order to leave comments, you need to log in
How to add a target to SCNCamera?
How to add a target to SCNCamera? In any position, the camera must always be aimed at the point of zero coordinates.
So far my code is this:
// create and add a camera to the scene
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(x: 0, y: 0, z: 20)
scene.rootNode.addChildNode(cameraNode)
Answer the question
In order to leave comments, you need to log in
I solved the issue in the following way:
// create and add a camera to the scene
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
//let cameraRoot = SCNNode()
cameraNode.position = SCNVector3(x: 0, y: 10, z: 20)
//cameraRoot.addChildNode(cameraNode)
scene.rootNode.addChildNode(cameraNode)
// setup a target object
let sphere = SCNSphere(radius: 0)
let sphereNode = SCNNode(geometry: sphere)
scene.rootNode.addChildNode(sphereNode)
// put a constraint on the camera
let targetNode = SCNLookAtConstraint(target: sphereNode)
targetNode.isGimbalLockEnabled = true
cameraNode.constraints = [targetNode]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question