Search Unity

Keeping the object/3D Model on the screen even when the target is lost (UNITY + Vuforia)

Discussion in 'Scripting' started by arvrappps, May 22, 2017.

  1. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
    Hi,

    I want to Keep the object/3D Model on the center of mobile screen even when the target is lost (on tracking lost()) and when target found last tracked image model should disappear. I'm using unity.

    I tried to follow cloudreco sample but not able to that properly.
    for centering of screen i'm using :

    GameObject lost = GameObject.Find ("IT"+mTrackableBehaviour.TrackableName);

    lost.transform.position=Camera.main.ScreenToWorldPoint(new Vector3(Screen.width/2, Screen.height/2, Camera.main.nearClipPlane) );


    I have around 10 image targets with max simultaneous images tracking set to 1.
    looking for solution.

    Thanks !
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    The first issue I see with your ScreenToWorldPoint call is using Camera.main.nearClipPlane for your Z coordinate. That Z coordinate represents the distance from the camera the object would be placed, and nearClipPlane would by definition put it closer to the camera than what could be rendered. Plus, that's a really small number, so I'm guessing the object is getting placed around your camera, not in front of it.

    Try a larger value there. How large it should be depends on your scale in Vuforia - if your target's "size" is 10, then try 20 or 30, for example (which will place it 2 or 3 times further from the camera as the target is wide).

    Also, don't use GameObject.Find.
     
  3. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
    @StarManta
    Thanks for the reply.
    I want to keep my 3d model on screen even after marker is removed ...
    If I disable on tracking lost function then my model appears on edges where it lost the tracking... I'm not able to do it right.
    Please tell me how to keep my 3d model on screen after tracking lost.
    And thanks for the suggestion for camera positioning