Jump animation bool randomly going to false while jumping

Hi All,

I am trying to implement jumping into my simple 2D platformer. The way I am handling the animations is that I’m checking if the player is colliding with the ground. If so, I set my isJumping parameter to false. If he’s not colliding with the ground, I set it to true.

I am running into an issue where about 50% of the time that I jump, my isJumping parameter is setting to true, then immediately back to false. I have messed around with implementations for ~3 hours and can’t seem to figure out why or a way around this issue.

See attached picture for Unity info.

Below is the relevant code snippet for checking for grounding and setting the animation parameter. The jumpPressedRemember and that stuff is to handle coyote time.

void Update() {
        bool bGrounded = Physics2D.OverlapCircle(m_GroundCheck.position, k_GroundedRadius, m_WhatIsGround);

        fGroundedRemember -= Time.deltaTime;
        if (bGrounded) {
            fGroundedRemember = fGroundedRememberTime;
            animator.SetBool("isJumping", false);
        }

        fJumpPressedRemember -= Time.deltaTime;
        if (Input.GetButtonDown("Jump")) {
            fJumpPressedRemember = fJumpPressedRememberTime;
        }

        if (Input.GetButtonUp("Jump")) {
            if (myRB.velocity.y > 0) {
                myRB.velocity = new Vector2(myRB.velocity.x, myRB.velocity.y * fCutJumpHeight);
            }
        }


        if ((fJumpPressedRemember > 0) && (fGroundedRemember > 0)) {
            fJumpPressedRemember = 0;
            fGroundedRemember = 0;
            animator.SetBool("isJumping", true);
            myRB.velocity = new Vector2(myRB.velocity.x, fJumpVelocity);
        }

The most likely culprit is that you’re performing physics in Update instead of FixedUpdate. Remember that Update is called once per frame and FixedUpdate is called 0…n times per frame depending on the physics timestep accumulator. What’s likely happening is that you’ve set your jump velocity in the previous frame, then the next frame a FixedUpdate tick hasn’t run yet, so the rigidbody hasn’t actually moved and Update thinks you’re grounded again and then the next frame your velocity kicks in and you’re visually jumping.