3
\$\begingroup\$

I did a sample existing code to control animation using animation.I dragged and dropped a character into the scene then I added a Animator to it and added the animator controller.Below I have given the screen short of the animation enter image description here

Then I have attached the following code to it

Animator animator;

int eatHash=Animator.StringToHash("ideal");

int stateHash=Animator.StringToHash("Base Layer.pickbothfork");

void Start () {
    animator = GetComponent<Animator>();
}

// Update is called once per frame
void Update () {
    //animator.SetBool ("isEat", true);
    float move = Input.GetAxis ("Vertical");
    animator.SetFloat ("Speed",move);

    AnimatorStateInfo stateinfo = animator.GetCurrentAnimatorStateInfo (0);
    if (Input.GetKeyDown(KeyCode.Space))
    {
        Debug.Log ("clicked spacebar");
        animator.SetTrigger(eatHash);
    }
}

The problem here is the above code is working,when I run the project the animation is getting played one after the another according to the state diagram.But when I click on the space bar the trigger function(jump animation ) is not working

if (Input.GetKeyDown(KeyCode.Space))
{
    Debug.Log ("clicked spacebar");
    animator.SetTrigger(eatHash);
}

Can anybody please help me finding solution for it

\$\endgroup\$
3
  • \$\begingroup\$ In the above state machine, is the "ideal" event the event that goes between the "Idle" and "jump_pose" states? \$\endgroup\$ Commented Sep 10, 2014 at 15:04
  • \$\begingroup\$ ys its a state flow from idle to jump_pose and so on \$\endgroup\$ Commented Sep 11, 2014 at 5:21
  • \$\begingroup\$ Can you provide the infomations about parameters (which were cut off on the image.. ) and about the transition's activation conditions ? \$\endgroup\$
    – tc07
    Commented Sep 23, 2016 at 19:30

2 Answers 2

1
\$\begingroup\$

If you want to go from walk or run animation to the jump animation you have to create a specific transition for each of those. You can edit the transitions by right-clicking them and selecting edit.

\$\endgroup\$
2
  • \$\begingroup\$ I have edited the transition.The animation is being working as stated idle -> jump_pose ->run ->walk.The problem is when i click on space bar the animation should be idle.I mean if the animation currently is walk when i click on space bar it should be idle \$\endgroup\$ Commented Sep 11, 2014 at 5:30
  • 1
    \$\begingroup\$ Then you need an event that goes from walk to idle. Or manually call anim.CrossFade("Idle"). \$\endgroup\$ Commented Sep 12, 2014 at 14:43
1
\$\begingroup\$

You don't have any transitions from run/walk back to jump. Look at the arrows; you only have a transition from jump to run, not back from run to jump.

In other words, transitions are not bi-directional; they're only one way. If you want a transition that goes back to a previous state, then you need another arrow.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .