Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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: http://www.box2d.org/forum/download/file.php?mode=view&id=1044&sid=86e8772dc965cba215f9a16cca2839e4

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

Thanks

share|improve this question
1  
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
3  
You need anti-aliasing –  Notabene Jul 21 '11 at 16:54
1  
No I do not need it. –  Milo Jul 21 '11 at 18:33
    
@Milo yeah you do. It would most likely fix the problem. –  AttackingHobo Jul 21 '11 at 18:52
2  
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
show 5 more comments

2 Answers 2

up vote 7 down vote accepted

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.

share|improve this answer
    
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
1  
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
add comment

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.
#define b2_polygonRadius        (2.0f * b2_linearSlop)

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;
    polygon.SetAsBox(width*0.5-polygon.m_radius, height*0.5-polygon.m_radius, b2Vec2(offsetX, offsetY), angle);
    fixture.shape = &polygon;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.