Pages

Mecanim Tryout

Let's make Unity's Ethan shake hand with a very very hot invisible chick. Press 'X' to shake hands
Very simple state machine










Idle to Shake Transition




















Shake To Idle Transition




















Flowchart-
Idle keeps looping
When "Shake" is set >> transition to Shake
Stay there until exit-time has occurred and Shake is set to false (It should be play once)

So we do need to write some code for this, Mecanim can't variables and stuff I think (not sure).

The trick for using "Boolean" trigger in Mecanim is -
Check if we are in proper state.
Set Flag
Next loop - Unset flag

using UnityEngine;
using System.Collections;
public class Shake : MonoBehaviour
{
private Animator anim;
private bool isShaking;
public int Count;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update ()
{
if (isShaking)
{
anim.SetBool("Shake", false);
isShaking = false;
}
if (anim.GetCurrentAnimatorStateInfo(0).nameHash == Animator.StringToHash("Base Layer.Idle")
&& Input.GetKeyDown(KeyCode.X))
{
Count++;
isShaking = true;
anim.SetBool("Shake", true);
Debug.Log(Count);
}
}
}
view raw Ethan Shaking hosted with ❤ by GitHub
Animation re-targeting is cool and all.. but I'm not so impressed with the design / architecture yet. Looks to me like it's gonna end up being a big pile of mess with lot of patch-works everywhere. Hope I'm wrong for my own sake..

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.