2
votes

I'm using libgdx and jBox2D for the first time (though I've used Box2D in other environments before).

I created a large dynamic body, and two smaller static bodies for it to land on. My bodies never seem to touch. Instead, it seems like the system is creating really tiny bodies in between my bodies ... and I don't know why!

The top half of the image below shows a collision in progress (right side), and one about to happen (left side, un-shaded shape).

The bottom half of the image below is a few steps later. The large shaded shape has rotated about the first collision point and has "collided" with the un-shaded shape.

At the site of each collision is a little red dot that seems to be preventing the shapes from touching. I've tried this at multiple scales and the results are similar. I've tried googling and searching this site for someone with the same problem with no luck.

Picture of jBox2D misbehavior

2

2 Answers

1
votes

Each polygon has an extra small "radius", described in the documentation:

    /**
     * The radius of the polygon/edge shape skin. This should not be modified.
     * Making this smaller means polygons will have and insufficient for
     * continuous collision. Making it larger may create artifacts for vertex
     * collision.
     */
    public static float polygonRadius = (2.0f * linearSlop);

Which uses linearSlop, defined:

    /**
     * A small length used as a collision and constraint tolerance. Usually it
     * is chosen to be numerically significant, but visually insignificant.
     */
    public static float linearSlop = 0.005f;

So this means you'll want to either

  • Increase your drawing sizes to accomidate this, or
  • Make your coordinate system larger so this space (0.02) is not noticeable.

I would suggest the second. If your coordinate system is too small (or big), it can have other performance implications.

0
votes

So, as near as I can figure, this situation is a minor (but important) detail related to polygon skins.

(http://www.box2d.org/manual.html#_Toc258082970 ... scroll down to the bottom of 4.4)

The polygons have an invisible skin around them that is used to prevent inter-penetration, but this skin is not drawn by the Box2D debug view. Since I sized my textures with respect to the polygon - and not the polygon plus the skin - there is a visible gap.

Long story short, we have to account for the skins on our own.

If you've got more info or a better explanation, I'd love to hear it! :-)