Search code examples
c#unity-game-engineaugmented-realityvuforia

Tracking the Number of Image Targets available at the particular moment


Using Vuforia's Unity Extension, I have a strong grip on the basics. But then I stumbled upon this video that shows a really cool feature for AR in Chemistry. I'd like to know how it detects a certain Image Target, and how it is able to animate like that.

I tried to recreate the video and have a H cards, and one O card on my scene. But I am unable to figure out what to do next.

If I script something it would probably go something like

if(TrackerManager.Instance.GetTracker.HCard() && 
   TrackerManager.Instance.GetTracker.OCard())
{
  //Put in my animation
}

But this does not work. Basically, I can't find a single target with that syntax and there's no Vuforia Log on how to do the same.

How do I initialize animation when the two ImageTargets are in close by.

Looking forward to the answer


Solution

  • the idea is to get the objects to move to each other, i don't know if if(TrackerManager.Instance.GetTracker.HCard() && TrackerManager.Instance.GetTracker.OCard()) works or not but you can try giving tags to your objects and using gameobject = GameObject.Find ("yourtag"); to get instances of them. you also need to add colliders to the objects and using the OnCollisionEnter function in unity you test if the two objects have collided then all you do is

    H.transform.position = Vector3.MoveTowards (H.transform.position, O.transform.position, 0.1f);
    O.transform.position = Vector3.MoveTowards (H.transform.position, O.transform.position, 0.1f);      
    

    so this way the two objects will move towards each other . Finally when the objects collide meaning O.transform.position == H.transform.position you deactivate the two objects and instantiate a new one O.SetActive(false); H.SetActive(false); NewObj = Instantiate (NewObj, sphere.transform.position, Quaternion.identity) as GameObject;

    I hope this is clear enough.