0

I've got a Box2DWeb simulation with a custom shape body but it doesn't interact with other bodies at all. The debug draw shows that the collision is detected but it has no effect. Reading about custom shapes I didn't find anything to set up to enable the collision, I have no idea of what is wrong. The custom shape body is created like this, I also posted the example here:

bodyDef = new b2BodyDef;
bodyDef.type = b2Body.b2_dynamicBody;
bodyDef.position.x = canvas.width/30/2;
bodyDef.position.y = 2;
body = world.CreateBody(bodyDef);
v = [[2,0],
[2,2],
[0,2],
[0,3],
[2,3],
[2,5],
[3,5],
[3,3],
[5,3],
[5,2],
[3,2],
[3,0]];
vecs = [];
for(i=0;i<v.length;i++){
cc = new b2Vec2();
cc.Set(v[i][0],v[i][1]);
vecs[i] = cc;
}
fixDef.shape = new b2PolygonShape;
fixDef.shape.SetAsArray(vecs,vecs.length);
body.CreateFixture(fixDef);
lelloman
  • 13,883
  • 5
  • 63
  • 85

1 Answers1

1

Box2D only knows how to deal with convex polygons, so you'll have to make the cross shape from more than one fixture to account for the concave sections. For example, you could have two long rectangles that cross over each other in the middle.

iforce2d
  • 8,194
  • 3
  • 29
  • 40