//This is the code idk why but it only jumps once but everything seems correct please help me I’m stuck for days
void Update()
{
//move
Movement();
if (IsGrounded())
{
Jump();
canDoubleJump = true;
}
else if (canDoubleJump == true)
{
Jump();
canDoubleJump = false;
}
void Movement()
{
if (Input.GetKey(KeyCode.D))
rb.velocity = new Vector2(moveForce, rb.velocity.y);
else if (Input.GetKey(KeyCode.A))
rb.velocity = new Vector2(-moveForce, rb.velocity.y);
else
rb.velocity = new Vector2(0, rb.velocity.y);
}
void Jump()
{
if (Input.GetKeyDown(KeyCode.Space))
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
}
}
}
bool IsGrounded()
{
Vector2 position = transform.position;
Vector2 direction = Vector2.down;
float distance = 1.0f;
RaycastHit2D hit = Physics2D.Raycast(position, direction, distance, ground);
if (hit.collider != null)
{
return true;
}
return false;
}