"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

calculating AR Camera distance to gameobject/fiducial

Dear Community We are doing a project in unity for android. In this project we need to check the distance from the AR camera to the gameobject/fiducial in order to make some of the objects invisible when you move the phone closer to the fiducial and some other object visible in stead. You can call it some sort of "level of detail". So my question is how to calculate the distance between AR camera with fiducial/gameobject. So far im using something like this: void Update() { float dist = Vector3.Distance(AR.position, transform.position); } But it dont seem to help. Hope some of you may be able to help us. we will appreciate it a lot.

Seems like you're close, you want the distance between the ARCamera's transform.position and the Trackable's transform.position. For the best results I suggest doing this in the OnTrackablesUpdated callback of the ITrackerEventHandler interface.

Thank you for your reply. I am calculating the distance in a script attached to the image target. It seems to disappear and reappear when i run it in unity and drag the AR camera away and towards the imagetarget with no problems. But it does not do so when i build and run it on the phone.

This seems to work fine, although I had to change the distance check to 250 for it to work reasonably with the ImageTargets sample. Note that this script is going to overwrite the DefaultTrackableEventHandler, which turns the renderers on/off when the target is tracked/lost.