I’m making a 2d fighting game. Most of the time, the jump works. But ever 8 jumps or so, it will go a different height, rather super high or just higher than usual. Even if I’m not moving horizontally, it’ll seem to be working fine and the jump will work multiple times in a row, but then it’ll jump to the moon. I cannot figure out why. It doesn’t have anything to do with the coyotetime or jump buffering because that was made after. Help?
if(Input.GetButton(“Jump”))
{
jumpBufferCounter = jumpBufferTime;
}
else
{
jumpBufferCounter -= Time.deltaTime;
}
if(isGrounded)
{
fallSpeed = fallCounter;
hangTimeCounter = hangTime;
// anim.SetBool("isJumping, false);
// anim.SetBool("isFalling, false);
}
else
{
FastFall();
hangTimeCounter -= Time.deltaTime;
}
if(rb.velocity.y > 0 && !isGrounded)
{
isJumping = true;
}
else{
isJumping = false;
}
if(rb.velocity.y < 0 && !isGrounded)
{
isFalling = true;
}
else{
isFalling = false;
}
#endregion
// determine if grounded]
isGrounded = Physics2D.Raycast(transform.position, Vector2.down, groundLength, groundLayer);
if((jumpBufferCounter > 0f) && (hangTimeCounter > 0f))
{
Jump();
hangTimeCounter = 0;
}
}
// draws line to 0.6 below (distance of raycast)
private void OnDrawGizmos()
{
Gizmos.color = Color.red;
Gizmos.DrawLine(transform.position, transform.position + Vector3.down * groundLength);
}
void Jump()
{
rb.velocity = new Vector2(rb.velocity.x, 0);
rb.AddForce(Vector2.up * jumpSpeed * Time.deltaTime, ForceMode2D.Impulse); // instand force
jumpBufferCounter = 0f;
}