Jumping Animation

Hi! So in the lesson listed above Rick was making a “TileVania”, and he stated, ‘I’m fine with jump using Running animation’. I tried to implement Jumping animation based on what I’ve learned in previous lessons and only got this far:

void OnJump(InputValue value)
    {
        if (!playerCollider.IsTouchingLayers(LayerMask.GetMask("Ground"))) { return; }

        if (value.isPressed)
        {
            playerRb2d.velocity += new Vector2(0f, jumpForce);

            playerAnimator.SetBool("isJumping", true);
        }

    }

Also I made sure Jump animation isn’t looping and has Exit Time enabled (put it on 1).

Now, the problem is after making a jump and playing the correct animation it freezes on the last frame, and after that my character is idling, running and jumping on that single frame.

I know it is because I never set the bool isJumping back to false. But I tried some ideas and never really figured out how to do it properly without creating another bool isGrounded, which would make another check and only then reset the state to Idle.

Maybe someone can help me figure out this one?

P.S. Excuse me for my mistakes, if there are any

Hi,

First of all, do not apologise for making mistakes. We all know that you didn’t do them on purpose. Furthermore, programming and developing games is all about solving problems. A problem is an opportunity to learn more. :slight_smile:

I’m not sure if I understood your problem correctly. If the animation “freezes”, this usually means that it reached the last keyframe and does not loop or transition to another state/animation. Did you enable “Has Exit” on the transition arrow back to the “idle” state?

What you could try instead of setting “isJumping” to false is to replace the bool with a trigger parameter in the animator. And in your code, you could try to use SetTrigger instead of SetBool. Theoretically, once the player is not touching the ground anymore, the “isJumping” trigger gets automatically set to false.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms