Log in or register to post comments

How to Trigger Events with Certain Image Targets

September 22, 2016 - 1:24pm #1

Hi all!

 

So, I have 3 Image Targets, and I want each of them to Set an Animation trigger, or turn a Boolean to true, how can I differentiate each one out so I can create my script?

My guess is that I have to get them first, but I'm not sure how Vuforia calls them, or differentiates them.

 

Thanks in advance! 

How to Trigger Events with Certain Image Targets

October 3, 2016 - 11:19pm #3

Hi Dastariel,

if I understand you correctly, depending on the need you can try the below two alternatives:

1) access the tracking status from any script, maybe inside Update or FoxedUpdate Monobehaviour methods:

  foreach (TrackableBehaviour atb in TrackerManager.Instance.GetStateManager().GetActiveTrackableBehaviours())

  {

    if (atb.CurrentStatus == TrackableBehaviour.Status.TRACKED || atb.CurrentStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)

    {

      // here goes the code for your animation

    }

  }

As you can see, the code simply filters the tracked and extended tracked trackables, from the active ones. In your case you should have 3 trackables, If you have more than 3, it is because in Vuforia the active trackables are not the just the ones assigned to the ImageTargets, but all trackables contained in databases enabled inside the ARCamera.

2) you can do something similar directly in the TrackableEventHandler attached tho your ImageTargert objects; there you will find the OnTrackableStateChanged, that handles the trackable's status changes: if you use the Vuforia default implementation, you will find that depending on status it will fire OnTrackingFound() or OnTrackingLost() where you may evaluate implementing the animation.

One thing: OnTrackingLost() is called during the initialization of Vuforia, so you have to make sure that your added code can run w/o problems during the initialization: use a flag taking care or this. 

 

Hope this helps; sorry for the long message: I see only now how long it is... cheers!

How to Trigger Events with Certain Image Targets

September 27, 2016 - 5:16pm #2

Hey Friend.

You got lookie with the script?

greetings.

 

Log in or register to post comments