Sub-State Machines and 2 Different Idle Animations
I currently have 2 sub-state machines: one for a "docile" state in which I default to a "normal idle" animation, but can also walk and jump, and a second "action" state in which I default to an "alert idle" animation. The action sub-state machine can play attack and cast animations, but also has the ability to walk around and jump (just to be clear, both state machines contain the exact same walk and jump animations). Before transitioning back to docile, all animations in the action state default back to the "alert idle" animation, which has an exit time of 5 seconds.
Here's what I'd like to have happen:
I want my player's "normal idle" animation described above to be replaced with the "alert idle" animation whenever my player takes damage or engages in combat for 5 seconds after these events occur. However, I also want my player to be able to walk around or jump, and still go back to the "alert idle" animation if my player has engaged in some form of combat within the past 5 seconds. Imagine this simple scenario:
Player is in "normal idle" stance -->
Player attacks, playing the attack animation -->
Attack animation ends, and player is now standing still in the "alert idle" stance for 3 seconds -->
After these 3 seconds the player walks (the "walk" animation plays) for 1 second -->
The player goes back to standing still, and the "alert idle" animation still plays for 1 more second -->
The player is still standing still, but since 5 seconds have passed the "normal idle" animation resumes.
Here's my problem:
I haven't been able to figure out a way to do this because I am not sure how to use the animator to set this up properly. I currently have it so that both sub-state machines have walk and jump animations, but since the action state machine goes back to the "alert idle" stance after walking or jumping, and since the "alert idle" stance has an exit time of 5 seconds, I can perpetually be in the action state machine as long as I keep moving around. If I remove the walk and jump animations and just transition back to the "docile" state machine I can't be alert for the full 5 seconds if I walk or jump (since these animations would default back to the docile state).
Is there a way to make it so that my alert animation will always play for 5 seconds after I'm in combat, but also make that timer reset if, for example, I have 1 second left on the alert timer, but then attack again? I have had this problem for a long time and simply don't understand how to resolve it in Unity.
Can a script be written that forces a switch between states based on a timer?
Thank you in advance for any help you may be able to give me.
Your answer
Follow this Question
Related Questions
State transition to Idle, Issues with directional walk to idle anim; 0 Answers
Cycle NPC animations after certain time has passed 0 Answers
Setting transform.eulerAngles doesn't work in a StateMachineBehaviour script 0 Answers
How to play idle animations only when player is idle 0 Answers
how to smoothly transition between animations in the "Any State" state machine. 1 Answer