Hello! I have infinite jump problem, please help me!
void Update()
{
if (Input.GetButtonDown("Jump") && isGrounded)
{
jump = true;
jumpForce = 1000;
}
else
{
jump = false;
jumpForce = 0;
}
}
void FixedUpdate()
{
isGrounded = Physics2D.OverlapCircle(groundCheck.position, radius, groundLayer);
float h = Input.GetAxis("Horizontal");
anim.SetFloat("Speed", Mathf.Abs(h));
if (h * Fb2d.velocity.x < maxSpeed)
Fb2d.AddForce(Vector2.right * h * moveForce);
if (Mathf.Abs(Fb2d.velocity.x) > maxSpeed)
Fb2d.velocity = new Vector2(Mathf.Sign(Fb2d.velocity.x) * maxSpeed, Fb2d.velocity.y);
if (h > 0 && !facingRight)
Flip();
else if (h < 0 && facingRight)
Flip();
if (jump && isGrounded)
{
if (Fb2d.velocity.y < maxJumpVelocity)
{
Fb2d.AddForce(Vector2.up * jumpForce);
jump = true;
jumpForce = 1000;
}
else
{
// Otherwise stop jumping
jump = false;
jumpForce = 0;
}
}
}
Comment
Please update your question to contain more information about your problem, describe what is happening and what you think should be happening ins$$anonymous$$d.
Put a Debug.Log("stopped jumping");
under // Otherwise stop jumping
to see if it ever happens.
You don't have to guess and wonder what is happening in your code. You can use various debugging methods like adding breakpoints and Debug.Log() calls to find out.
Your answer
Follow this Question
Related Questions
How to stop my character from infinite jumping? 2 Answers
Player Is infinite jumping 1 Answer
how to stop infinite jumping in air? 0 Answers
how to jump in a 2D game 2 Answers
How i make a ball jump where i point with my mouse?[3D] 0 Answers