- Home /
How do I stop Infinte jumping?
I'm making an player-controller script & it allows you to jump infinitly. Does anyone know how to fix this? This is my code:
float leftRight; float jump; public float speed; public float jumpSpeed;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
leftRight = Input.GetAxis("Horizontal");
jump = Input.GetAxis("Jump");
transform.Translate(Vector3.right * Time.deltaTime * speed * leftRight);
transform.Translate(Vector3.up * Time.deltaTime * jumpSpeed * jump);
}
}
Answer by Mikepopularpro · Apr 02, 2020 at 10:16 PM
oh some of the code didn't show the box. well the things at the top were variables.
Answer by guy1687621 · Apr 02, 2020 at 10:33 PM
you have to do a boolean check. check is your character on the ground.
Answer by Shakarane · Apr 02, 2020 at 11:05 PM
Create an imaginary circle underneath the player and check if the circle is colliding with anything
void CheckIfGrounded() { // Create an object called collider // "collider"'s value is the collider "OverlapCircle" returns // Overlap circle creates an imaginary circle. When something collides with it, collider = whatever object it collided with Collider2D collider = Physics2D.OverlapCircle(isGroundedChecker.position, checkGroundRadius, groundLayer); if (collider != null) { isGrounded = true; } else { isGrounded = false; } }
Your answer
Follow this Question
Related Questions
Player jump not working correctly 1 Answer
Player sticks to ground occasionally after trying to jump 0 Answers
I need help with a movement script 1 Answer
How do I check if a character is grounded? 2 Answers
Unity my player does not jump 1 Answer