- Home /
Animator trigger always plays, even after I reset
Been messing with this for hours but I can't quite seem to get it to work as I would like.
I have a firing animation and an idle animation. My idea is that:
IF the player is idle and fires, play fire animation.
IF player does anything else, stop firing animation and perform given animation
I have actually achieved the two above, but the problem is that if I do anything else, like jump, then the firing animation is performed AFTER the jump... instead, the firing animation should be scrapped if anything else (jump or walk) occurs.
This is how it looks:
Where Fired (the trigger) is the condition which stars characterFire. And the script:
void Update()
{
if (grounded && Input.GetAxis("Jump") > 0)
{
grounded = false;
playerAnimator.SetBool("isGrounded", grounded);
playerRigidBody.AddForce(new Vector2(0, jumpHeight));
playerAnimator.ResetTrigger("Fired"); // Doesn't work
}
if (Input.GetAxisRaw("Fire1") > 0)
{
//playerAnimator.SetTrigger("fired");
fireRocket();
}
}
void fireRocket()
{
if (Time.time > nextFire)
{
playerAnimator.SetTrigger("Fired");
nextFire = Time.time + fireRate;
StartCoroutine(fireCoroutine());
}
}
IEnumerator fireCoroutine()
{
// used to sync animation to firing of bullet
yield return new WaitForSeconds(fireDelay);
if (facingRight)
{
Instantiate(bullet, gunTip.position, Quaternion.Euler(new Vector3(0, 0, 0)));
}
else if (!facingRight)
{
Instantiate(bullet, gunTip.position, Quaternion.Euler(new Vector3(0, 0, 180f)));
}
}
I also tried messing with the animator interruption source, but to no avail.
Your answer
Follow this Question
Related Questions
2D Animation does not start 1 Answer
How to avoid double trigger behavior? 0 Answers
Parameter does not exist 3 Answers
Animation Keypress Trigger Problem 0 Answers
How to Play an animation state on an animator controller on collision? 1 Answer