I have a 2-stage melee attack logic:
- on pressing Fire1 the character arms
the hit, and should maintain the
arming while Fire1 is pressed - on releasing Fire1 the character releases the blow and does damage to
enemies, or if Fire2 is pressed
arming is cancelled and we return to
IDLE
In mecanim, I have the following setup (with scripting logic included):
- IDLE state → Input.GetButton(“Fire1”) → ARMED State
- ARMED State → Input.GetButtonUp(“Fire1”) - > HITTING State
- OR
- ARMED State → Input.GetButtonDown(“Fire2”) → cancel arming and return to IDLE
State - HITTING State → exit time → IDLE State
The issue is that if Fire1 gets released during the transition from IDLE to ARMED, the whole process breaks down. We are now in the ARMED state (since we did press Fire1 to trigger the transition to it) but we can’t get to Fire1 UP without pressing it down again. Moreover, we get stuck in the ARMED state while Fire1 is NOT pressed as it should be.
What am I missing?
Just combine the two previous methods with Animator. GetNextAnimatorStateInfo: http://docs.unity3d.com/Documentation//ScriptReference/Animator.GetNextAnimatorStateInfo.html
– tanoshimiWow, this might be it. Thanks, I'll check it out and get back to you. :)
– norse950[I converted your answer to a comment]. And this is all taking place in a secondary animation layer, not in the base layer? (which would be GetCurrentAnimatorStateInfo(0) etc. ? You might need to post a picture of your Animator window, and please show the set of conditions in the transitions from IDLE -> ARMED and back again
– tanoshimiOK, I eventually figured it out, after a lot of trial and error, including identifying particular transitions by name. All I had to do was to change the HITTING condition, from if(Input.GetButtonUp("Fire1")) { anim.SetBool("Hit", true); } else { anim.SetBool("Hit", false); } to if(!Input.GetButton("Fire1")) { anim.SetBool("Hit", true); } else { anim.SetBool("Hit", false); } God damn it :(
– norse950