Sensors in Box2D (or how to make a basic platformer)

After playing around with Box2D, I tried to make a simple platformer. After setting up a static body to represent the ground, and a dynamic box to represent the character, I ran into a problem – how do you know whether your character can jump? Essentially you need to know whether he is standing on the ground. If he is on the ground, and the player presses some button, you can do your jumping physics (set a velocity or apply a force/impulse). One way to approach this problem is to use sensors. Sensors are fixtures that don’t affect the result of an actual collision, but can detect when a collision would have occurred. If you place a sensor under your character’s main area, you can detect when there is something right under him. Here is a diagram:
sensor_diagram
Continue reading Sensors in Box2D (or how to make a basic platformer)