Prashant Tukadiya
Prashant Tukadiya

Reputation: 16456

ARkit How to get exact point of node from tap location

I have following code on tap gesture on sceneview

 let location = gesture.location(in: self.sceneView)
 let hitTestScene = self.sceneView.hitTest(location, options:nil)
 if let first = hitTestScene.first  {

  }

I am able to get node from first

What I want is Suppose I have wall node which is SCNPlane or SCNBox with very big height.

Now If User tap on particular location let say on half of node. I want to that point in that node. So the question is With sceneView.hitTest I can get node which tapped but I want the location in node. like where that exactly tapped.

So I can measure height from origin to tapped location

Any Suggestion will be appreciated

Upvotes: 1

Views: 506

Answers (1)

Prashant Tukadiya
Prashant Tukadiya

Reputation: 16456

We can get position to the hit node with the SCNHitTestResult localCoordinates property.

let location =  self.centerImage.center
let hitTestScene = self.sceneView.hitTest(location, options:nil)
if let first = hitTestScene.first  {
   print("localCoordinates in tapped node is", first.localCoordinates ) 
}

Upvotes: 1

Related Questions