hit testing

I am experimenting with the code in Session 605


I want to see what I am tapping and next I want to add animation.


I am using this code:


@IBAction func onTap(_ sender: UITapGestureRecognizer) {

let tapLocation = sender.location(in: arView)

print("I am here at onTap")

// Get the entity at the location we've tapped, if one exists

if let object = arView.entity(at: tapLocation) {

// For testing purposes, print the name of the tapped entity

print(object.name)

// Add interaction code here

}

}


I have generated collisions with this:

boxAnchor.generateCollisionShapes(recursive: true)


I can get behaviors to work from reality composer, but I don't get anything back from the onTap action. How do I get things responding in the onTap function so that I can add code based animation, etc.?


thanks,

Dale

Accepted Reply

adding this makes the onTap work..


let tapGesture = UITapGestureRecognizer(target: self, action:#selector(onTap))

arView.addGestureRecognizer(tapGesture)


thanks,

Dale

Replies

adding this makes the onTap work..


let tapGesture = UITapGestureRecognizer(target: self, action:#selector(onTap))

arView.addGestureRecognizer(tapGesture)


thanks,

Dale