Search code examples
swiftscenekitaugmented-realityarkit

Detect SCNNode with camera only


Let's say I draw a circle in the middle of my screen, to use it as a target. If I point this circle to a node, how is it possible for ARKit to detect it?

For now I'm using the tap method

 @IBAction func tapHandler(_ sender: UITapGestureRecognizer) {
    let viewTouchLocation:CGPoint = sender.location(in: sceneView)
    guard let result = sceneView.hitTest(viewTouchLocation, options: nil).first else {
        return
    }
    // ...etc
}

which works really well, but it would be so much better to detect a node just by pointing the camera at it.


Solution

  • let screenRect = UIScreen.main.bounds
    let screenWidth = screenRect.size.width
    let screenHeight = screenRect.size.height
    
    let location = CGPoint(x:screenWidth/2,y:screenHeight/2)
    

    use location in hittest