# Character keeps jumping infinitely on walls

I’m making a 2d platformer and my player is able to jump infinitely when against a wall.

This is my script for the player movement:

``````using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
private float horizontal;
public float speed = 2f;
public float jumpingPower = 6f;
private bool isFacingRight = true;

[SerializeField] private Rigidbody2D rb;
[SerializeField] private BoxCollider2D feetCollider; // Use a BoxCollider2D for ground check

void Update()
{
horizontal = Input.GetAxisRaw("Horizontal");

if (Input.GetButtonDown("Jump") && IsGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, jumpingPower);
}

if (Input.GetButtonUp("Jump") && rb.velocity.y > 0f)
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}

Flip();
}

private void FixedUpdate()
{
rb.velocity = new Vector2(horizontal * speed, rb.velocity.y);
}

private bool IsGrounded()
{
// Use Physics2D.OverlapBox for more accurate ground detection
return Physics2D.OverlapBox(feetCollider.bounds.center, feetCollider.bounds.size, 0f, groundLayer);
}

private void Flip()
{
if (isFacingRight && horizontal < 0f || !isFacingRight && horizontal > 0f)
{
isFacingRight = !isFacingRight;
Vector3 localScale = transform.localScale;
localScale.x *= -1f;
transform.localScale = localScale;
}
}
}
``````

### Does anyone have a solution for this?

in your IsGrounded function you have to subtract a bit on the sides. Try something like this:

``````bool IsGrounded()
{
return Physics2D.BoxCast(
coll.bounds.center,
coll.bounds.size - new Vector3(.1f, 0f, 0),
0f,
Vector2.down,
.1f,
jumpableGround
);
}
``````

for me this worked i think it would work the same for `OverlapBox`.