- Sort Posts
- 12 replies
- Last post
Re: Playing animation with unity3d
Re: Playing animation with unity3d
I was using the animation field of the TrackableEventHandler script but then I needed to animate 2 objects. That field will only take one object (all animated children will be ignored). Ended up having to also use
GameObject go = GameObject.Find("JEEP");
go.animation.Play("Move");
which worked fine.
Re: Playing animation with unity3d
Thanks Tyro for your responses.
The animations in my own model didn't show up in the inspector.
To evade the confusion with my own model I tried Spartan King model which is available for free in Unity Asset store. I can see all the animations loaded. But the animation doesn't play when marker is detected.
I have tried this kind of code in TrackableEventHandler without any luck.
private void OnTrackingFound() { Renderer[] rendererComponents = GetComponentsInChildren<Renderer>(); Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " found"); // Enable rendering: foreach (Renderer component in rendererComponents) { component.enabled = true; Debug.Log("Component name " + component.name ); if(component.animation) { component.animation.Play(); Debug.Log("Animation playing " + component.animation.isPlaying); } } }
Re: Playing animation with unity3d
What if my animation is baked?
Unity has problems w/ animations that use inverse kinematics (IK). This is why baking to FK ( Forward Kinematics ) is recommended. But you need to inspect the model and remove any IK rigging afterwards. Also it's advised to bake in your native 3D environment (e.g. Maya) and then import. Otherwise baking, in and of itself, isn't a problem.
Have you confirmed that the animation is even importing? Can you see it in the inspector a/o Animation View.
Here's the API for the Animation component.
http://unity3d.com/support/documentation/ScriptReference/Animation.html
Re: Playing animation with unity3d
I'm not sure how baked animations behave differently, you should still be able to loop them.
You can expose script member variables in the Inspector view by making them public. In this case, add this to the top of the TrackableEventHandler script:
public Animation m_animation;
Select your trackable. There should now be a field named "animation" under the attached TrackableEventHandler script. You can drag any game object with an animation component onto this field (e.g. your model).
- Kim
Re: Playing animation with unity3d
Perhaps your animation is only playing once at startup and you're missing it. Trying looping the animation as a test:
http://unity3d.com/support/documentation/ScriptReference/Animation-wrapMode.html
If you want the animation to only play once the marker comes into view you can modify the TrackableEventHandler script provided with the sample applications. Try passing the animation into this script and calling m_animation.Play() in the OnTrackingFound method.
- Kim
I have use this in unity 5.3 (vuforia 5.5)