I’m trying to create some basic platformer mechanics. I recently tried to add a fast fall ability where the player can fall quickly to the ground mid-jump if they press down. The code also prevents you from jumping if you’re holding down.
void Update() {
if((grounded || !doubleJump) && Input.GetButtonDown("Jump") && cannotJump == false) {
Jump();
}
//Fast Fall
if (grounded == false) {
if (Input.GetAxis("Vertical") < 0) {
rigidbody2D.AddForce(new Vector2(0, -fastFall));
}
}
//Prevent Jump if Fast Fall is held
if (grounded && (Input.GetAxis("Vertical") < 0)){
cannotJump = true;
}
if (grounded && (Input.GetAxis("Vertical") >= 0)) {
cannotJump = false;
}
}
However, if I fast fall or tap down while on the ground, it takes several frames before I can jump again. It’s supposed to prevent me from jumping only while the button is being held. It’s a noticeable difference (a good ~10 frames) so it’s not that I’m accidentally pressing both down and jump at the same time.