Check collision on ground

I used Adobe Illustrator to draw the ground. Save it as XML file.
Parse this XML to my code.

I created my main character as rectangle.

I don't know whether my charactor is "in the air" or "on ground".
I used to check GetLinearVelocity().y == 0, but still have some trouble when the "collision point with ground" is on the hill. If the player keep go/down hill after touching ground,
Image
Image
mainCharBody->GetLinearVelocity().y != 0
Code:
if (mainCharBody->GetLinearVelocity().y == 0 && onAir == YES) {
      [mainChar setDisplayFrame:frame];
      onAir = NO;
   }

I thought about the contactlistener. But it will makes error when the mainCharacter touch the wall.

Anybody can help me?
Attach a small sensor to the bottom of your player to detect when it is on top of something.
Thank you but i don't know how to make a sensor?
I recommend you don't use a rectangle for your character.. I did the same initially and ran into some problems...

The better (and seemingly more widely adopted) approach is to use a "capsule" shape... basically a rectangle with a circle shape on the bottom (and top if required).

So your player character would be comprised of 2 (or 3) shapes, one being a rectangle, the other being a circle shape positioned such that the equator of the circle aligned with the bottom of the rectangle. Any contact with the bottom circle and your ground shape(s) would effectively mean the player was touching ground. You may register multiple contacts so don't use a boolean to determine if he's on the ground.. use a count. So every time the bottom circle contacts your ground shape: increment, and every time contact is lost: decrement. When the count is zero you're not touching the ground.

This approach has the advantage of providing a simple way of detecting ground, particularly on slopes where a bottom sensor under a rectangle may not be touching, and also makes it easier to traverse "bumpy" ground (as it seems you have from your screenshots.)

Be aware however, that there are some issues with using this approach. My game currently suffers from these problems but I am currently just living with it as it only happens occasionally.
I did it. Thank u 😀

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