I created an empty node and added a set of nodes to the empty node and finally adding that to my root node. After which, I create a camera node as shown below. I am trying to add a feature to my scenekit app where by when a user tap a node, the camera moves and focus on that node. In my handleTap function, I am trying to get the position of the node and then fix the camera to that position but it is not working. Any suggestions?
//snippet
var emptyNode = SCNNode()
emptyNode.addChildNode(Node)
rootNode.addChildNode(emptyNode)
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3(1,0,10)
rootNode.addChildNode(cameraNode)
func handleTap(recognizer: UITapGestureRecognizer) {
let location = recognizer.locationInView(sceneView)
let hits = sceneView!.hitTest(location, options: nil)
if let tap = hits.first?.node {
tappNode = tap
myScene?.cameraNode.position = tappNode.position
}
EDIT
So, I am making a little progress but I still cannot figure out the position of my node. The Updated code is given below. What I have done is to create a new node and attached a camera to it. That node is then added to the tap node as a child.I still cannot get the position of the tap node within the context of empty node.
let cameraNode = SCNNode()
cameraNode.name = "cameraNode"
cameraNode.camera = SCNCamera()
cameraNode.position = SCNVector3Make(1,0,10)
tappNode.addChildNode(cameraNode)
SCNTransaction.begin()
SCNTransaction.setAnimationDuration(3.0)
SCNTransaction.setCompletionBlock() {
print("done")
}
sceneView!.pointOfView = cameraNode
SCNTransaction.commit()