# How do I detect ledges?

In my game, I'd like my character to be able to grab and hold onto ledges, and to be able to pull themselves up if there's room to do so.

How do I detect if there's a ledge, and if the character has enough space to climb up?

The video for Overgrowth Alpha 132 shows how they implemented ledge climbing.

Their method should work in any engine, even 2D engines where you'd use a rectangle and circle instead of a cylinder and sphere.

Their ledge detection involves two parts:

### Wall detection (using the sphere)

The game checks if the player's currently colliding with a wall. If there's a wall, there might be ledges the player can grab onto. The second part takes over to analyse the ledges.

### Ledge detection (using the cylinder)

If the player's contacting a wall, a cylinder is swept downwards from a certain distance above the player's position until it touches a ledge. That certain distance is the maximum reach height of the player: if the character can reach a ledge at most 1 meter above their position, the sweep starts at that height. This determines three things:

• Whether a ledge exists above the player
• The ledge's height
• Whether there is room for the player to climb up onto the ledge, considering the cylinder occupies the same horizontal space as the player.

(You also need to determine there's nothing in the way between the ledge and the player, such as a hard floor or ceiling above them.)

• Amazing method, and fantastic example +1 Commented Oct 20, 2012 at 12:19
• "a cylinder is swept downwards from a certain distance above the player's position" What distance? This is very important when dealing with indoor environments (you'd intersect the ceiling by accident).
– Tara
Commented May 17, 2015 at 3:13
• @Dudeson in the past I've used a raycast to initially find the ledge surface, before following-up with a volume check to verify that there's enough unobstructed room to climb up. Since the raycast is directional it doesn't read ceilings as false positives - though it could still get snagged on the next floor up if the origin is much too high.. The exact metrics will depend on a lot of particulars of each game - the character size, arm reach, clearance in the level design, falling speeds, etc. Commented Dec 21, 2016 at 16:09
• @DMGregory Good idea with the ray cast!
– Tara
Commented Dec 22, 2016 at 4:57