Here are some questions that come up very often that don't really need a whole tutorial topic to discuss them, but still warrant mentioning somewhere to help save time and frustration when others come across them.

Why can't I get bodies to go faster than a certain speed?

There is a maximum movement limit of 2.0 units per time step. This might seem like a really slow speed to have as an upper limit, but this a distance per time step, not a velocity given in units per second. Units in Box2D are tuned to be meters, so at a typical framerate of 60Hz a body covering 2 units per timestep is moving at 120 m/s or 432 km/h (270 mph), which is not really that slow. This value is built into the library's core settings.

Why is there always a small gap between bodies?

When shapes overlap they are pushed apart so that they don't overlap, but many cases (particularly with stacked objects) make it difficult to keep this situation stable. The box on top moves down due to gravity and touches the box underneath, then gets pushed back up, and so on, forever. Apart from looking terrible from all the jittering around, this will never stabilize and wastes computing time since the bodies will never be able to sleep.

a stack of boxes with very small gaps where they rest on each other

To address this problem there is a tiny space around shapes which is used as a buffer, in which two adjacent shapes can agree that they are touching, but there is no overlap so no correction needs to be made - they can smile at each other and relax. This is a core setting in the physics engine and while it can be adjusted, you should really know what you are doing before you do.

Why do bodies lose speed after bouncing even when their restitution is set to 1?

Due to the way the correcting impulses are calculated for a collision, a small amount of energy can actually be lost, especially in cases where a body collides with more than one other body at the same time. This means that a perfectly elastic collision is not guaranteed (well, the same goes for real-life situations). In very simple scenarios you may be able to adjust the velocity of the involved bodies after the collision has completed.

I'm applying an upwards force to cancel gravity, but the body still moves slowly downwards...

Check that you are applying the force before the first time step. If you have the applyForce call after the world's step call in your main loop, the body will get one time step at normal gravity and it will have a chance to move down a tiny bit before the gravity is cancelled. Just change the order of the calls in the main loop so that the applyForce comes first.

Why do kinematic bodies not respond to impulses or forces?

Unlike most of the Box2D world, kinematic bodies are something we do not have in real life. Although they can move like a dynamic body, they have no mass, which means they have infinite momentum and cannot be pushed or bumped around by anything. Usually the whole point of using a kinematic body is that you don't want it to be affected by for example your player jumping on it, so it wouldn't be much use if it was affected by forces or impulses now would it? Kinematic body movements must be controlled by setting linear and angular velocities directly.

Why do very slow collisions cause no rebound?

To help keep the simulation stable very small bounces are treated as inelastic, regardless of the restitution settings you have given the fixtures. The most common case where this becomes a problem is snooker/billiards games, where even a slow collision with the side walls or the other balls should be calculated accurately. In b2Settings.h you can change the default value (b2_velocityThreshold) for the minimum velocity to consider inelastic. Changing this to a much smaller value should not usually cause any problems.

How can I get the points of shapes to render them?

You can get the polygon vertices from a shape like this:

if (b2Shape_GetType(shapeId) === b2ShapeType.e_polygon) {
    const polygon = b2Shape_GetPolygon(shapeId);
    const vertexCount = polygon.count;

    for (let i = 0; i < vertexCount; i++) {
        // Get vertex in local coordinates
        const localVertex = polygon.vertices[i];

        // Get vertex in world coordinates
        const bodyId = b2Shape_GetBody(shapeId);
        const worldVertex = b2Body_GetWorldPoint(bodyId, localVertex);
    }
}

How can I tell which version of Box2D I'm using?

You can check the version information using:

const version = b2GetVersion();
console.log(`Version: ${version.major}.${version.minor}.${version.revision}`);

Why do I get a contact for two shapes when they're not touching?

You may get this when checking contact data from b2Body_GetContactData() or similar functions. The existence of a contact does not mean that the two shapes are actually touching - it only means their AABBs (bounding boxes) are overlapping. If you want to know if the shapes themselves are touching you can check the contact flags:

const contactData = new Array(b2Body_GetContactCapacity(bodyId));
const contactCount = b2Body_GetContactData(bodyId, contactData, contactData.length);

for (let i = 0; i < contactCount; i++) {
    const contact = contactData[i];
    const isTouching = (contact.flags & b2ContactFlags.touching) !== 0;
}

See the 'anatomy of a collision' topic for more details.

Credits

This tutorial is adapted from an original piece of work created by Chris Campbell and is used under license.