Log in or register to post comments

Start animation when target is found

March 29, 2017 - 4:06pm #1

I've seen several posts on this but most are fairly old and I'm having a tough time applying them to my Unity 5.5 and Vuforia 6.2.

I have imported an FBX file with animation and I've succeeded in getting the animation to run in an AR environment. Yay!

But, the animation begins as soon as the app starts. I want the animation to wait until the target image is found by the AR Camera.

Can someone get me heading on the right track?

Is coding the only way to do this? I can do some coding, but hoping not to...

Thanks.

 

Start animation when target is found

August 16, 2018 - 2:44am #4

I would not recommand using video playback for 2d animation with Vuforia because it's heavy hardware consumption and managing transparency (alpha) may be tricky (but it's perfectly possible with specific shader). It can works according smartphone type, for example Galaxy A3 2017 can play maximum of 2 videos on a scene according my tests and experiences. Probably higher range smartphones will be able to read more videos at once (especialy those compatible with Google ARCore).

The big advantage of using videos for 2D animations is the very good compression rate and smaller footprints into the APK.

 

Using spritesheets with PVR compressions is an alternative, with much better results, you can manage more than 20 sprites animations at the same time on a Vuforia scene without any slow down performances, even of low range grade smartphones. I would recommand using tools like Texture Packer with the Unity plug-In, it will manage all the tricky works for you to create sprites animations for Unity - Vuforia. Be aware of the Z axis depth, put your ARCamera at -2 Z axis for example, your marker at -1 and your sprites / 2d animations at -1.5, they will appear on the top of your markers, like if they are floating in the space. Last point to check is the scale of your elements, your animations must be to scale 1 or less to avoid any pixalizations during the rendering,you have to manage the scale of your markers according that (my markers are around 0.3 scale for my animations at 1 scale).

Then you just have to put your gameobject with animators as a child of your ImageTarget and modify the function to include the presence of animators children into your scene. Here is an example of my function on a working example:

protected virtual void OnTrackingFound()

    {

        var rendererComponents = GetComponentsInChildren<Renderer>(true);

        var colliderComponents = GetComponentsInChildren<Collider>(true);

        var canvasComponents = GetComponentsInChildren<Canvas>(true);

  var animatorComponents = GetComponentsInChildren<Animator>(true);

  //var animatorComponentsbis = GetComponents<Animator>();

        // Enable rendering:

        foreach (var component in rendererComponents)

            component.enabled = true;

        // Enable colliders:

        foreach (var component in colliderComponents)

            component.enabled = true;

        // Enable canvas':

        foreach (var component in canvasComponents)

            component.enabled = true;

  foreach (var component in animatorComponents)

  {

   component.enabled = true;

   component.Play ("CoinDrop");

   //m_Animator.Play("CoinDrop");

  }



    }

 

You can play like that any 2D animations from spritesheets very easily into your Vuforia scene, it's simple and powerfull ! All your animation can be easily controlled with Animators and will follow smoothly your Image Targets very well.

Good luck,

 

Pierre

Start animation when target is found

February 3, 2018 - 6:06pm #3

public class EnableAnimations : MonoBehaviour, ITrackableEventHandler

{

    private TrackableBehaviour mTrackableBehaviour;

    public Animator animationClips;

   

    void Start()

    {

        mTrackableBehaviour = GetComponent<TrackableBehaviour>();

        if (mTrackableBehaviour)

        {

            mTrackableBehaviour.RegisterTrackableEventHandler(this);

        }

    }

    public void OnTrackableStateChanged(

                                    TrackableBehaviour.Status previousStatus,

                                    TrackableBehaviour.Status newStatus)

    {

        if (newStatus == TrackableBehaviour.Status.DETECTED ||

            newStatus == TrackableBehaviour.Status.TRACKED ||

            newStatus == TrackableBehaviour.Status.EXTENDED_TRACKED)

        {

            // Play  when target is found

            animationClips.enabled = true;

        }

        else

        {

            // Stop  when target is lost

            animationClips.enabled = false;

        }

    }

}  

Start animation when target is found

March 30, 2017 - 7:01am #2

Hi Hardinly,

 

You can try video playback sample code which is available in vuforia. Video playback initially detect the image target then relevant video will be played. So you can customize the code as you want (after the image target was found, you can redirect the curret page to your animation page).

 

https://developer.vuforia.com/forum/faq/unity-how-do-i-create-simple-videoplayback-app

https://developer.vuforia.com/downloads/samples

 

Regards,

Muhilan

Log in or register to post comments