0

I tried to model a tetris shape with the SetAsArray function of box2d. But the shapes are not colliding correctly with other bodies, sometimes falling through, sometimes diving in. No problems with square or circle shapes.

    fixDef.shape.SetAsArray([
        new b2Vec2(-1,1.5),
        new b2Vec2(-1,-1.5),
        new b2Vec2(1,-1.5),
        new b2Vec2(1,-0.5),
        new b2Vec2(0,-0.5),
        new b2Vec2(0,1.5)],6
    ); // Tetris shape

    bodyDef.position.Set(7,0);
    var body=world.CreateBody(bodyDef);
    body.CreateFixture(fixDef);

I made a fiddle to show the effect:

http://jsfiddle.net/lavisrap/JrzPH/598/

Michael
  • 6,823
  • 11
  • 54
  • 84

1 Answers1

1

From the Box2D manual: "Polygon shapes are solid convex polygons. A polygon is convex when all line segments connecting two points in the interior do not cross any edge of the polygon." http://www.box2d.org/manual.html

iforce2d
  • 8,194
  • 3
  • 29
  • 40