How to detect if SCNBox was touched in scenekit? I am building a VR app
Asked
Active
Viewed 316 times
1
-
2Possible 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 Answers
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