Extent Angles

I am building a platformer and am trying to determine if a surface is ground or a wall. I can get this working pretty well using a sensor as the "feet", but I'd like to keep all bodies to a single shape if I can.

I had a theory that if I can get access the extent that my hero collided with, I could check its angle and determine if it's ground or a wall. Is there a way that i can do this?

If not, do you foresee a better way to determine ground/wall using a single shape for the hero?

Thanks!
if you are using an actor class for your userdata, you can add a type property to it. Then all you need to do is subclass b2ContactListener and set it into the world. In your custom contact listener, check the actors involved in the collision( using the userdata ) and add it to a contactstack for later processing.

In your update after the world step, check the contact stack for collisions you are interested in.
Thank you, however a single rectangle can be either a wall or ground depending on where the hero collides with it. If the hero collides with the side, then it's a wall. If the hero collides with the top, then it's a floor.

I am using an actor class as my user data, and I am also using categories.
Ok, I think I understand what you are getting at now. I would still use the contact listener. When you get your objects back, you could use the position of the contact point to determine if its a wall of floor.
Yes, that's what I'm thinking. I know how to get access to the contact point's position property, but that doesn't tell me anything about the angle of the line it's touching. I don't see any other way of deciphering if it's a wall or floor besides getting the angle of the line. However, I don't know how to use that value to get the angle of the line (or basically, the angle of two extent vectors). Any code hints?
If your contact listener is like this:

public override function Add(point:b2ContactPoint):void {

look at "point.normal" for the vector of the contact.

(0, -1) is a floor (0, 1) a ceiling and (-1, 0) and (1, 0) are walls.

but you'll probably want to use a range, because often it's not exactly thos values.
Thank you, I will look into that and see what values the normal gives me. I found something last night that gives me the exact angle that I need, although I haven't profiled it for speed yet.

Basically, I can find out which line the point is on because it will be the only line whose x, y extents surround the contact point. In other words, the contact point will be in between the the two x and y values of the line. Then I can do simple vector math to figure out the angle of the line.

Your way may be easier as long as it provides reliable results.
Wow, this seems to work great, but only about 90% of the time. On fairly often occasions, the value passed in is different and far outside my threshold. Any idea why?
On my way home I had a theory about the inconsistency with the collision normal. My guess is that The collision normal is always calculated using "shape1" to "shape2". And since we never know which shape "shape1" will be, I have a feeling that sometimes the collision normal is giving me the angle of the platform and sometimes it's the hero. If this is true, I can't really think how to guarantee that I'm getting the collision normal for the platform.

If I jump onto an angled surface, sometimes I get [0, 1] (which seems to be the value of the bottom of the hero's shape) and sometimes I get a more expected number (that comes out to the proper angle for the surface). Since there aren't two collision normals passed into the collision data, any ideas on how to get this to work?
What I do is I give all my actors an id. My player has 'ident = "player"' and all my terrain has 'ident = "ter"'.
In my contact listener I first look which actor each shape belongs to.

I have an ident priority list. Where player is at the top. If the player is not shape1 I switch the shapes around before I do all my other contact functions. When they are switched some properties of the point have to be inverted of course. When this is the case the point.normal has to be inverted ofcourse.

Original thread: https://box2d.org/forum/viewtopic.php?t=3417