Answer the question
In order to leave comments, you need to log in
The character sometimes jumps double the height. How to fix it?
The character randomly jumps to double the height from the prescribed one.
Wrote the most standard jump code:
private void Jump() {
rigidbody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
}
private void CheckGround() {
Collider2D[] colliders = Physics2D.OverlapCircleAll(transform.position, 0.3f);
isGrounded = colliders.Length > 1;
}
private void Update() {
if (isGrounded && Input.GetButton("Jump")) Jump();
}
private void FixedUpdate() {
CheckGround();
}
Answer the question
In order to leave comments, you need to log in
I solved this problem. As it turned out, everything was very simple... I called the jump function in Update, which is strongly discouraged... And along with framerate jumps and drops, the character jumped up and down. After I transferred all the movement to FixedUpdate, the problem capitulated.
Usually this situation occurs due to incorrect ground testing. For example, the player has not yet fallen, but the collider has already worked. Or the player fired a pistol and the bullet was detected as ground. Or a vertical wall hit the collider.
I advise you to rewrite under raycast under your feet. Also check if the impulse works correctly. Maybe your project is better off using speed.
private void Jump() {
rigidbody.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question