Can't make 2D Sprite jump

Hello,

I’ve tried using OnCollisonEnter as well as OnTriggerEnter but to no avail. I am simply unable to make my player successfully jump. I believe I’ve narrowed it down to the Colliders not working.

I got Box Colliders and Rigidbody2D on both my player character and the ground.

I’m using the following code:

void Update()
    {
        playerMovement();

        if(Input.GetKeyDown(KeyCode.Space) && isOnGround)
        {
            playerRb.AddForce(Vector2.up, ForceMode2D.Impulse);
            isOnGround = false;
        }
           
    }
void OnCollisionEnter2D(Collision collision)
     {
        if (collision.gameObject.tag  == "Ground")
        {
            isOnGround = true;
            Debug.Log("Player has jumped");
        }
     }

It could be the case that the force you are using is too little. Experiment multiplying it to 10 or 100 and see if it works.

Sounds like you’re just guessing randomly which is never going to end well. OnCollisionEnter and OnTriggerEnter are for 3D physics so they’ll only be called for that.

Have you done basic debugging by putting in a breakpoint here or even outputting something to the console log? I suspect not because the method signature is wrong.

As you can see in the docs, OnCollisionEnter2D is passed a Collision2D not a Collision (3D) one. The function you’ve got above won’t be called by Unity, it’s just a custom function you’ve created.