"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

Apply scale/translation after image target is lost

Hi,

I have an 3D model attached to a image target. What I want is to scale the model according to the camera's position, i.e. when I get closer to the model I want it to get larger and when I get far away it should get smaller. I searched the forums and tried two different solutions:

Solution 1:

I created a script and attached to the 3d model:

public class AR_Capsule : MonoBehaviour {

   float minimumDistance = 0;

   float maximumDistance = 3;

   float minimumDistanceScale = 0.3f;

    float maximumDistanceScale = 0.1f;  

    void Update()     {         float distance = (transform.position - Camera.main.transform.position).magnitude;         float norm = (distance - minimumDistance) / (maximumDistance - minimumDistance);         norm = Mathf.Clamp01(norm);

        Vector3 minScale = Vector3.one * maximumDistanceScale;         Vector3 maxScale = Vector3.one * minimumDistanceScale;

        transform.localScale = Vector3.Lerp(maxScale, minScale, norm);

   }

}

Solution 2:

public class AR_Capsule : MonoBehaviour {

   public float speed = 10f;

    void Update()     {         transform.Translate(0, 0,(-1 * Input.acceleration.z * speed * Time.deltaTime));

   }

}

Both solution works when the image target is visible. But when I lose the target from sight, then the object stays still and camera position is always (0.0, 0.0, 0.0). 

Do you have any idea why the object freezes when the target is lost?

I am developing for Epson Moverio bt-300 and working with vuforia eyewear sample app.

 

Thanks.