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);
}