Possible Duplicate:
How do I detect ledges?

I'm working on a 2D platformer using XNA and Farseer. I would like the player's character to be able to grab and climb up ledges. Detecting a collision between the player and the side of a wall is simple enough with the OnCollision delegate, but I have to admit I'm a bit stumped on how to detect that there's enough clearance for the PC to mount the ledge.

Essentially, I want to ensure there's an appropriately sized rectangle above and to the left or right of the PC (depending on their direction) and I'm not sure how I would check for such a space.

Any suggestions on how to determine there is nothing in the simulated world within some bounding rectangle?


2 Answers 2


The video for Overgrowth Alpha 132 shows how they implemented ledge climbing: http://www.youtube.com/watch?v=GFu44oeLYPI

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. This can determine 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.
  • 1
    \$\begingroup\$ Good answer. The downwards sweep can also be optimized by making sure ledges are always a multiple of a certain height, in overgrowth of course, this is not the case but may be possible for a platformer. \$\endgroup\$ Commented Aug 3, 2011 at 9:25
  • 3
    \$\begingroup\$ +1. Would give +10 for giving Overgrowth some publicity, but that's not possible :P \$\endgroup\$
    – TravisG
    Commented Aug 3, 2011 at 10:58
  • \$\begingroup\$ In that case, it looks like I need the World.RayCast() method in Farseer, so I can cast a ray downwards from some height above and to the side of the player, and ensure the first Fixture it collides with is the ledge edge. \$\endgroup\$
    – Thorn G
    Commented Aug 3, 2011 at 22:21

Well, you already have the tools, you just need to think of it differently. Rather than thinking trying to find empty space, you just need to find space with no collisions. Basically, all you have to do is test the area above the player with a rectangle the size of the player, and then if there are collisions, the player can't climb up. If there aren't collisions, the space is open and the player can get up.


Not the answer you're looking for? Browse other questions tagged .