My Jump animation doesn't transition to the next one (2D)

Hi, I’m newbie in Unity.

My problem is that the jump animation doesn’t stop playing until a second later when I stop moving the character, if I jump and then continuously move my character he will remain in the jump animation(Which is just one frame long) even after touching the ground until I stop moving him. If I just jump without moving back and forth, it will correctly transition to the next animation(idle animation). In every other situation everything works well, like running and then dying after hitting an enemy.

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movimiento : MonoBehaviour
{
    private Rigidbody2D rb2D;
    private BoxCollider2D boxCollider2D;
    [SerializeField] private LayerMask layerMask;
    float moveSpeed = 40;
    float jumpForce = 17f;
    float horizontalMove;
    public Animator animator;
    private bool facingRight;
    private int health = 3;



 
    void Start()
    {
        rb2D = gameObject.GetComponent<Rigidbody2D>();
        boxCollider2D = transform.GetComponent<BoxCollider2D>();
    }


    void Update()
    {
        horizontalMove = Input.GetAxisRaw("Horizontal");
        animator.SetFloat("speed", Mathf.Abs(horizontalMove));

        if (IsGrounded() && Input.GetKeyDown(KeyCode.UpArrow))
        {
            rb2D.velocity = Vector2.up * jumpForce;
            animator.SetBool("IsJumping", true);
        }
       
        if(rb2D.velocity.y == 0)
        {
            animator.SetBool("IsJumping", false);
        }
    }

    private void FixedUpdate()
    {
        if(horizontalMove > 0.1f || horizontalMove < -0.1f)
        {
            rb2D.AddForce(new Vector2(horizontalMove * moveSpeed, 0f), ForceMode2D.Force);

        }

        if(horizontalMove<0 && facingRight && IsGrounded())
        {
            Flip();
        }
        else if(horizontalMove>0 && !facingRight && IsGrounded())
        {
            Flip();
        }

    }

    private bool IsGrounded()
    {
        RaycastHit2D raycastHit2D = Physics2D.BoxCast(boxCollider2D.bounds.center, boxCollider2D.bounds.size, 0f, Vector2.down, .1f, layerMask);
        return raycastHit2D.collider != null;
    }

    void Flip()
    {
        facingRight = !facingRight;
        transform.Rotate(0f, 180f, 0f);
    }

    public void byeBye()
    {
        Destroy(this);
    }




[IMG]https://files.fm/thumb_show.php?i=xum73rrwu[/IMG]

this is how my animator looks:

Add some debug.logs to figure out what is happening at each spot where you change the animator.SetBools. Also, why don’t you connect AnyState in your animator window to Idle and Run? From what i see now, you can only go to Idle and Run if you Jump.

I am now also seeing that you are setting the IsJumping animator bool to false only when the Y rigidbody velocity is exactly 0. You should have it be false when the player is grounded. Its best practice to avoid checking for specific velocities. If anything you should do < or > but not equal to.

“I am now also seeing that you are setting the IsJumping animator bool to false only when the Y rigidbody velocity is exactly 0.”
Seemingly that’s the problem, but when I change it to “if(IsGrounded())” my character doesn’t transition to the jump animation(But it debug my message):

void Update()
    {
        horizontalMove = Input.GetAxisRaw("Horizontal");
        animator.SetFloat("speed", Mathf.Abs(horizontalMove));

        if (IsGrounded() && Input.GetKeyDown(KeyCode.UpArrow))
        {
            rb2D.velocity = Vector2.up * jumpForce;
            animator.SetBool("IsJumping", true);
            Debug.Log("Is it working?");
        }
       
        if(IsGrounded())
        {
            animator.SetBool("IsJumping", false);
        }
    }

I dont understand the problem, but I tried this:

void Update()
    {
        horizontalMove = Input.GetAxisRaw("Horizontal");
        animator.SetFloat("speed", Mathf.Abs(horizontalMove));

        if (IsGrounded() && Input.GetKeyDown(KeyCode.UpArrow))
        {
            rb2D.velocity = Vector2.up * jumpForce;
            Debug.Log("Is it working?");
           
        }
       
        if(IsGrounded())
        {
            animator.SetBool("IsJumping", false);
        }else if (!IsGrounded())
        {
            animator.SetBool("IsJumping", true);
        }
    }

Now my character can run and jump well, but the death animation doesnt play at all. In the end, I edited part of the Death function that happen after de death animation and added “animator.SetBool(“IsJumping”, false);”. Seemingly everything is working fine, but I really don’t understand the problem and I will probably give me troubles later.

public void byeBye()
    {
        animator.SetBool("IsJumping", false);
        Destroy(this);
    }

Check out this nice foundational video for help with getting the animations set up with the movement logic

2D Movement in Unity (Tutorial) - YouTube