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:
Detect Open Space in Farseer
How do I detect ledges?

I'm making a 2D platformer with Box2D. The player needs to be able to grab onto a ledge and pull him/herself up.

Right now I have a sensor that extends in every direction from the upper half of the player's body.

The logic seems simple enough: if there are tiles inside the sensor and empty space above them, then it's a ledge and the game should act accordingly. The problem is that I can't figure out how to implement that logic with Box2D.

Anyone have any ideas?

share|improve this question

marked as duplicate by Jonathan Hobbs, Byte56, Josh Petrie, Noctrine Oct 20 '12 at 14:34

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.

    
I've answered this myself in another question which this would be a duplicate of. –  Jonathan Hobbs Oct 2 '12 at 23:12
add comment

2 Answers 2

up vote 4 down vote accepted

What I needed to do was have two sensors. One extending outward of the upper half of the body, one with the exact same dimensions right above it.

If the top sensor isn't colliding with anything, and the bottom sensor is, it's a ledge.

share|improve this answer
add comment

Since no one has answered, check here. It should be the same

http://www.box2d.org/forum/viewtopic.php?f=3&t=7352

http://www.iforce2d.net/b2dtut/sensors

share|improve this answer
3  
Those links only explain how to use sensors. I already understood that. I had trouble figuring out if what the sensor was colliding with was, in fact, a ledge. –  DormoTheNord Oct 2 '12 at 19:42
    
Hi Anonymous, and welcome to GDSE! Answers that are barely more than links are generally less than optimal, since the moment that forum topic is deleted or otherwise 404s, your answer becomes a lot less useful. It's better to actually provide an explanation in your answer. In this case, though, there's also nothing directly about ledge detection! I'm downvoting this answer. –  Jonathan Hobbs Oct 19 '12 at 0:34
add comment

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