My Player can 'Climb' walls, how do I stop this?

I have my collider set up so the player only jumps when in contact with the collider grid. However, if the player comes up against a wall, they can ‘climb’ it by spamming the jump button, as they are in contact with a collider.

I’ve experimented with zero friction physics material to no avail. All help is greatly appreciated!

private void Jump()

{
    
    if (!myCollider2D.IsTouchingLayers(LayerMask.GetMask("Ground")))
    {
        return;
    }
       
    Vector2 jumpVelocityToAdd = new Vector2(0, jumpSpeed);
        myRigidBody.velocity += jumpVelocityToAdd;
    
}

,I have a 2D collider set up which stops the jump input if the player isn’t in contact with any colliders, however, when up against a wall, the player can ‘climb’ a wall by pressing jump next to it. Have experimented with zero friction physics material to no avail.

All help appreciated :slight_smile:

private void Jump()

{
    
    if (!myCollider2D.IsTouchingLayers(LayerMask.GetMask("Ground")))
    {
        return;
    }
       
    Vector2 jumpVelocityToAdd = new Vector2(0, jumpSpeed);
        myRigidBody.velocity += jumpVelocityToAdd;
    
}

Hi @Bung86


You could try using the OverlapCircle function to detect if your player is in contact with the ground instead.


  1. Create an empty gameobject at the bottom-center of your player (make sure it is a child of your player gameobject, call the new empty gameobject something like “feet”)
  2. Create a function to detect if your player is grounded
  3. Use that function in your current code

   public bool IsGrounded() {
  Collider2D groundCheck = Physics2D.OverlapCircle(feet.position, 0.5f, LayerMask.GetMask("Ground"));

  if (groundCheck != null) return true;

     return false;
}

void Update(){
  if (Input.GetButtonDown("Jump")  && IsGrounded())
  {
      Vector2 jumpVelocityToAdd = new Vector2(0, jumpSpeed);
      myRigidBody.velocity += jumpVelocityToAdd;
  }
}

To finish off, just increase or decrease the 0.5f inside of the OverlapCircle function until it works :slight_smile:

Cheers!