How to detect if SCNBox was touched in scenekit?

320 Views Asked by At

How to detect if SCNBox was touched in scenekit? I am building a VR app

1

There are 1 best solutions below

0
Chris On

you can use this:

let tapGR = UITapGestureRecognizer(target: self, action: #selector(tapGesture(sender:)))
sceneView.addGestureRecognizer(tapGR)

@objc func tapGesture(sender: UITapGestureRecognizer) {

    let location: CGPoint = (sender.location(in: self.sceneView))
    let hits = self.sceneView.hitTest(location, options: nil)
    if let tappedNode : SCNNode = hits.first?.node {
        tappedNode.position.y += 0.5
        print(tappedNode)
    }
}