A
A
Alex2019-10-19 14:42:00
Unity
Alex, 2019-10-19 14:42:00

Why does Untiy2D double jump happen?

There is actually a jump code, but if you press Space quickly, the object can make a double jump

// Код самого войда 
 private void OnTriggerStay2D(Collider2D collision)
    {
        isGrounded = true;
        
    }

// И прыжок
 void FixedUpdate()
    {
      if(isGrounded == true && Input.GetKeyDown(KeyCode.Space))
        {
            rb.AddForce(Vector2.up * jumpForce);
            isGrounded = false;
        }
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2019-10-19
@SenderD

In general, if you add

private void OnTriggerExit2D(Collider2D collision)
    {
        isGrounded = false;

    }

and remove isGrounded = false; from if{}, then the double jump disappears...

A
Andrew Nodermann, 2019-10-19
@Lucian

Try swapping:

isGrounded = false;
rb.AddForce(Vector2.up * jumpForce);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question