我有一个带有自定义形状主体的 Box2DWeb 模拟,但它根本不与其他主体交互。调试图显示检测到碰撞但没有效果。阅读有关自定义形状的信息,我没有找到任何设置来启用碰撞,我不知道出了什么问题。自定义形状体是这样创建的,我也在此处发布了示例:
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);