Hobo
Hobo

Reputation: 1

jump animation ending too quickly in first jump

    void FixedUpdate()
    {
        moveInput = Input.GetAxis("Horizontal");
        rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
        anim.SetBool("isWalking", true);
        if (facingRight == false && moveInput>0)
        {
            flip();
        }
        else if (facingRight == true && moveInput < 0)
        {
            flip();
        }
        else if (moveInput == 0)
        {
            anim.SetBool("isWalking", false);
        }

        isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);

    }

    void Update()
    {
        if (isGrounded == true)
        {
            Debug.Log("is grounded");
            extraJumps = extraJumpValue;
            anim.SetBool("isJumping", false);
        }
        if (Input.GetKeyDown(KeyCode.Space) && extraJumps + 1.0f > 0)
        {
            jump();
            extraJumps--;
        }
    }

    void flip()
    {
        facingRight = !facingRight;
        Vector3 Scaler = transform.localScale;
        Scaler.x *= -1;
        transform.localScale = Scaler;
    }
    void jump()
    {
        rb.velocity = Vector2.up * jumpForce;
        anim.SetBool("isJumping", true);
    }
}

I just started to learn unity starting by following tutorials on YouTube. However I can't figure out why my jump animation is ending as soon as it starts on my first jump. On extra jumps it works fine. If you know how to fix this, pls help me.

Upvotes: 0

Views: 43

Answers (1)

vasmos
vasmos

Reputation: 2586

In your update loop you call Jump which sets

    anim.SetBool("isJumping", true);

and in your fixed update loop you have

    anim.SetBool("isWalking", true);

So immediately after calling Jump on the next 'FixedUpdate' you are setting the animation bool of iswalking, unless moveInput is 0. I can't see all your code or what is happening to moveInput but I can tell you this is where your problem is. You need to change the animations of this code:

    anim.SetBool("isWalking", true);
    if (facingRight == false && moveInput>0)
    {
        flip();
    }
    else if (facingRight == true && moveInput < 0)
    {
        flip();
    }
    else if (moveInput == 0)
    {
        anim.SetBool("isWalking", false);
    }

Upvotes: 1

Related Questions