playMaker

Author Topic: Playing attack animation with mecanim controller [SOLVED]  (Read 3497 times)

Grofit

  • Junior Playmaker
  • **
  • Posts: 73
Playing attack animation with mecanim controller [SOLVED]
« on: January 17, 2014, 05:13:39 AM »
I have a mecanim controller which has states for idle, walking, running an it all works fine. Now I wanted to add an attack animation, which currently just is 1 punching move, which is triggered from any state when the controller variable IsAttacking is true, once complete the animation flows back to idle.

In playmaker I have states for Idle, Walking, Running and now Attacking. However the problem is that whenever the attacking state is triggered it ends and goes back to idle instantly which does not play the attack animation.

The current setup is whenever mouse left button down occurs it raises an FSM event for "OnAttackButtonDown" which is a global transition into the Attacking state. The state sets the animator bool value IsAttacking to true, then after googling found that I should be using the GetAnimatorStateNameMatch (or similar name) action to find out if the state is still Attacking in the mecanim controller and when it no longer matches Attacking revert back to the Idle FSM state. The idle state resets the mecanim controller vars so it should no longer attack.

So I would expect logically the flow to be:

- User presses mouse button
- Animator IsAttacking is set to true
- Animator plays Attacking animation
- Animator stops playing Attacking animation
- FSM reverts to idle state
- Animator IsAttacking is set to false

I am not sure if I am going about this all the right way but I am still new to all this, but as it just seems to instantly flip back to idle without playing the animation I am just wondering if I am missing something or if there is a better way to do this?

Any advice would be great!
« Last Edit: January 18, 2014, 04:04:48 AM by Grofit »

Grofit

  • Junior Playmaker
  • **
  • Posts: 73
Re: Playing attack animation with mecanim controller
« Reply #1 on: January 18, 2014, 03:49:52 AM »
It seems if I just do "Animator Play" it does what I want, but now I have a follow up question which I will post in a new thread.