1

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

Andruino
  • 9
  • 1
  • 3
  • 2
    Possible duplicate of [Scenekit detecting User tapped object](http://stackoverflow.com/questions/26444524/scenekit-detecting-user-tapped-object) – James P Jul 29 '16 at 14:42

1 Answers1

0

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)
    }
}
Chris
  • 7,579
  • 3
  • 18
  • 38