Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

marked as duplicate by Josh Petrie, Noctrine Oct 20 '12 at 14:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers

up vote 14 down vote accepted

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.
share|improve this answer
1  
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. –  Jonathan Connell Aug 3 '11 at 9:25
3  
+1. Would give +10 for giving Overgrowth some publicity, but that's not possible :P –  TravisG Aug 3 '11 at 10:58
    
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. –  Tom G Aug 3 '11 at 22:21
add comment

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.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.