i am Beginner and i Need help with Jumping Animation please

i have Bug when i play the game Walking and Idle animation is totally fine but when i jump … Jump animation play and after character is not doing any animation at all
my Player script

photo of my Unity here Imgur: The magic of the Internet

i hope somebody will help me already i lost 2 days working on this code changing him few time i am newbie at Unity

Hi @BraniDev

Hint: to maximize probability to get an answer, it is best to attach both the images and code here permanently.

You can use code tags to format your code in your post and use Upload a File button next to Post Reply to attach images.

@BraniDev

You can edit your first post, no need to double post, and the code can be attached using code tags…

1 Like

i try to edit it but forum says i am a spammer i cannot edit the thread anymore … next time i will do it correct
can you help me with my issue?

void Update()
    {
        if (_grounded == true)
        {
            extraJumps = extraJumpsValue;
            m_Jump = true;

//check this for test and say what will be wrong here
m_Animator.SetBool("Jumping", false);
        }

great
when i jump is not playing animation but when i double jump it is playing normally and it come back to walk animation
so is good 50% is only playing when i double jumping (pressing 2x space)
so just fix this and i am good to go

ok, here is the delay between fixed update and update. The bool is switching back to false in the time as the player is flying up (because your circle check moving over the ground in not only one frame. I will think bit, how to prevent this.

ps. the simplest way were to add some time to prevent that the bool going false in next time

pps. or you can allow to change the bool if the players speed was negative.

but i just add your code i didnt delete anything what i have in my code… btw you are kida superhero to me now… thanks

i have no idea what to do can you write to code?

not sure if this will work, my scripts work almost never on first try :slight_smile:

ps. I have edited it bit

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


public class Player : MonoBehaviour
{

    [SerializeField]
    public float speed;
    private float moveInput;

    private Rigidbody2D rb;
    [SerializeField]
    public float jumpForce;

    private bool facingRight = true;

    private bool _resetJump = false;
    private bool _grounded = false;


    public Transform groundCheck;
    public float checkRadius;
    public LayerMask whatIsGround;

    private int extraJumps;
    public int extraJumpsValue;

    private PlayerAnimation _playerAnim;
    private SpriteRenderer _playerSprite;
    Animator m_Animator;
    bool m_Jump;

    //here new bool
    bool hasJumped = false;


    void Start()
    {
        extraJumps = extraJumpsValue;
        rb = GetComponent<Rigidbody2D>();
        _playerAnim = GetComponent<PlayerAnimation>();
        _playerSprite = GetComponentInChildren<SpriteRenderer>();
        m_Animator = GetComponentInChildren<Animator>();
        m_Jump = false;

    }

    void FixedUpdate()
    {
        _grounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);



        moveInput = Input.GetAxis("Horizontal");

        rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);

        if (facingRight == false && moveInput > 0)
        {
            Flip();
        }
        else if (facingRight == true && moveInput < 0)
        {
            Flip();
        }
        _playerAnim.Move(moveInput);


    }




    void Update()
    {

        //here check if the player is falling
        if (hasJumped && rb.velocity.y < 0)
        {
            hasJumped = false;
        }

        if (_grounded == true)
        {
            extraJumps = extraJumpsValue;
            m_Jump = true;

            //here allow the end the animation if the player is falling and the grounded is true
            if (!hasJumped && m_Animator.GetBool("Jumping"))
            {
                m_Animator.SetBool("Jumping", false);
            }

        }


        if (Input.GetKeyDown(KeyCode.Space) && extraJumps > 0)
        {
            rb.velocity = Vector2.up * jumpForce;
            extraJumps--;


            if (m_Jump == true)
                m_Animator.SetBool("Jumping", true);
            Debug.Log("playing jumping animation");


            //here your player has began the jump
            hasJumped = true;



        }
        // i think here somewhere is the bug...
        else if (Input.GetKeyDown(KeyCode.Space) && extraJumps == 0 && _grounded == true)
        {
            rb.velocity = Vector2.up * jumpForce;
            rb.velocity = new Vector2(rb.velocity.x, jumpForce);
            m_Animator.SetBool("Jumping", false);
            Debug.Log("I am Jumping");


        }


    }


    void Flip()
    {
        facingRight = !facingRight;
        Vector3 Scaler = transform.localScale;
        Scaler.x *= -1;
        transform.localScale = Scaler;

    }



}

here with wait time

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


public class Player : MonoBehaviour
{

    [SerializeField]
    public float speed;
    private float moveInput;

    private Rigidbody2D rb;
    [SerializeField]
    public float jumpForce;

    private bool facingRight = true;

    private bool _resetJump = false;
    private bool _grounded = false;


    public Transform groundCheck;
    public float checkRadius;
    public LayerMask whatIsGround;

    private int extraJumps;
    public int extraJumpsValue;

    private PlayerAnimation _playerAnim;
    private SpriteRenderer _playerSprite;
    Animator m_Animator;
    bool m_Jump;

    //here new bool
    bool hasJumped = false;


    void Start()
    {
        extraJumps = extraJumpsValue;
        rb = GetComponent<Rigidbody2D>();
        _playerAnim = GetComponent<PlayerAnimation>();
        _playerSprite = GetComponentInChildren<SpriteRenderer>();
        m_Animator = GetComponentInChildren<Animator>();
        m_Jump = false;

    }

    void FixedUpdate()
    {
        _grounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);



        moveInput = Input.GetAxis("Horizontal");

        rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);

        if (facingRight == false && moveInput > 0)
        {
            Flip();
        }
        else if (facingRight == true && moveInput < 0)
        {
            Flip();
        }
        _playerAnim.Move(moveInput);


    }




    void Update()
    {
        if (_grounded == true)
        {
            extraJumps = extraJumpsValue;
            m_Jump = true;

            //here allow to end the animation if some time was passed
            if (!hasJumped && m_Animator.GetBool("Jumping"))
            {
                m_Animator.SetBool("Jumping", false);
            }

        }


        if (Input.GetKeyDown(KeyCode.Space) && extraJumps > 0)
        {
            rb.velocity = Vector2.up * jumpForce;
            extraJumps--;


            if (m_Jump == true)
                m_Animator.SetBool("Jumping", true);
            Debug.Log("playing jumping animation");


            //here your player has began the jump
            if (!hasJumped)
            {
                hasJumped = true;
                StartCoroutine("WaitBitAfterJump");
            }



        }
        // i think here somewhere is the bug...
        else if (Input.GetKeyDown(KeyCode.Space) && extraJumps == 0 && _grounded == true)
        {
            rb.velocity = Vector2.up * jumpForce;
            rb.velocity = new Vector2(rb.velocity.x, jumpForce);
            m_Animator.SetBool("Jumping", false);
            Debug.Log("I am Jumping");


        }


    }


    void Flip()
    {
        facingRight = !facingRight;
        Vector3 Scaler = transform.localScale;
        Scaler.x *= -1;
        transform.localScale = Scaler;

    }

    //here new coroutine
    //wait for 1f seconds and change the bool
    //you can change it to lower value 0.5f
    IEnumerator WaitBitAfterJump ()
    {
        yield return new WaitForSeconds(1f);
        hasJumped = false;
    }

}

thank you again i should have a contant on you maybe next if i need help :slight_smile: