I created a SCNView
and want to use a UITapGestureRecognizer to move SCNNode
's around the view; however, the code I implemented doesn't seem to be working. The nodes move sometimes, but they never move to the correct spot. Does anyone know what I am doing wrong here?
@objc func handleTapGesture(_ gesture: UITapGestureRecognizer) {
let location = gesture.location(in: scnView)
guard let result = self.scnView?.hitTest(location, options: nil).first else { return }
let transform = result.simdModelTransform
let newPosition = SCNVector3(transform.columns.3.x, node.position.y, transform.columns.3.z)
node.position = newPosition
}