Reputation: 1082
I have an app that has a random ARKit anchor placed in the environment.
I want to make a simple arrow or pointer that would point to which direction the anchor is if it is currently off the screen.
Has anyone had to do anything similar? Or, do you know of any example code that I could take a look at to help me implement this feature?
Thanks!
Upvotes: 0
Views: 727
Reputation: 562
You could create a 3D arrow, add it to your camera node so that it’s always visible and give it a lookAt(your random anchor world position) constraint.
If your anchor is visible (use visibleNodes) then hide the arrow.
Example video : https://twitter.com/londonrom/status/1060282275932372992?s=21
Upvotes: 0
Reputation: 21
If you use the pointer as a UIImage you can use: self.yourSceneView.projectPoint(yourNode.worldPosition) to get the position on screen for your node and than calculate where the pointer needs to point
if the pointer is another SCNNode than use yourPointerNode.look(at: yourAnchorNode) to change the orientation of the pointer to point towards the node on the anchor
in both cases update the locations in func session(_ session: ARSession, didUpdate frame: ARFrame) function
Upvotes: 2