- Home /
How to compute real life distance between Android camera and an AR marker
Hello to all. I' m trying hard to finish an AR (Augmented Reality) project, but I cannot implement the following described functionality. I need to show a gameObject, a 3d model, upon recognition of the AR camera that runs the NyARToolkit plugin, inside a certain distance, e.g 1.5 meters (is it equal to 1.5 units in unity word?).
As soon as the user moves above the 1.5 meters distance form the marker on wall, the application should load a different level, e.g. with another 3d model.
I searched the forum for something similar and Googled also, but could not find something to much my needs on how to implement this functionality.
I though of coding, a RayCast coming from the AR camera gameObject and hitting the gameObject "model" on a collider, so it is on "true" state. When I move the gameObject "model" away, as if the user would moved away form the marker, I get next level loading, but only on play mode.
How can I match the Unity AR camera to the real device camera, so when I move the Android mobile way from marker, I get next level loaded?
Following is the code snippet I have tried, that needs to be matched to Android device also, to work as it should:
#pragma strict
var onMarker : GameObject
function Update () {
var hit : RaycastHit;
var backwards = transform.TransformDirection(Vector3.back);
Debug.DrawRay(transform.position, -backwards*10, Color.red);
if(Physics.Raycast(transform.position, -backwards, hit, 10))
if(hit.collider.gameObject.name =="Camera"){
onMarker.SetActiveRecursively(true);
}
else{
onMarker.SetActiveRecursively(false);
Application.LoadLevel ("scene1");
}
}
If someone is kind enough to post a sample or a tutorial, It would be great, as I' m a novice in Unity and scripting. Thank you all in advance for your time and answers.