# Rectangles render with gaps in between them (Box2D)

Right now I create my boxes where 1 meter is 85 pixels. Gravity is 10. And

                        fixtureDef.restitution = 0.1f;
fixtureDef.friction = 0.5f;
fixtureDef.density = 1.0f;


The problem I'm having is illustrated in the image I have provided:

As you can see, there is a small gap between many, but not all the crates. What could cause this?

Thanks

• You have a graphical error so you post a question about your physics engine instead of the graphics engine? – AttackingHobo Jul 21 '11 at 16:44
• You need anti-aliasing – Notabene Jul 21 '11 at 16:54
• No I do not need it. – jmasterx Jul 21 '11 at 18:33
• @Milo yeah you do. It would most likely fix the problem. – AttackingHobo Jul 21 '11 at 18:52
• Yes, it's cheating, but so is the entire physics engine. Who cares, it works. "If it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck" :p – Maik Semder Jul 21 '11 at 19:55

I guess that's some issue in box2d, there is such a bug to increase performance. since more accuracy needs much more computational power. to fix that issue I guess you only need reduce box physical sizes (for example you can create a 84px*84px rectangle for a 86px*86px image). you can also fade the pixels in the edges to get better results.

• Many physics engines use a small cheat distance and especially for when objects come to rest. Your oversize rectangle would make a nice fix, I'll wager. – Patrick Hughes Jul 21 '11 at 20:50
• Box2d does, in fact, use a small 'cheat distance', and that's probably what's causing the boxes to not-quite-touch. The extra space around objects is so that floating point precision errors don't make items penetrate. – Blecki Jul 23 '11 at 0:39

Just wanted to say that Ali is right, Box2D has a macro on this - I'll paste it here:

/// The radius of the polygon/edge shape skin. This should not be modified. Making
/// this smaller means polygons will have an insufficient buffer for continuous collision.
/// Making it larger may create artifacts for vertex collision.


This value is assigned to a new b2PolygonShape's m_radius field in the constructor. Subtracting this value from your body during creation is a trivial solution to resolve the gap glitch:

    b2PolygonShape polygon;