Box2DWeb,PolygonShape.SetAsVector未检测碰撞

Box2DWeb,PolygonShape.SetAsVector未检测碰撞,vector,collision,shape,box2dweb,Vector,Collision,Shape,Box2dweb,这是序言 如果我用SetAsBox定义棒球棒,没有问题 当我使用SetAsVector定义它时,会发生这种奇怪的情况 this.view = new createjs.Bitmap("hammer.png"); this.view.regX = 0; this.view.regY = 0; var fixDef = new box2d.b2FixtureDef(); fixDef.density = 5.0; fixDef.friction = 0.5; fixDef.restitution

这是序言

如果我用SetAsBox定义棒球棒,没有问题

当我使用SetAsVector定义它时,会发生这种奇怪的情况

this.view = new createjs.Bitmap("hammer.png");
this.view.regX = 0;
this.view.regY = 0;

var fixDef = new box2d.b2FixtureDef();
fixDef.density = 5.0;
fixDef.friction = 0.5;
fixDef.restitution = 0.8;
var bodyDef = new box2d.b2BodyDef();
bodyDef.type = box2d.b2Body.b2_kinematicBody;
fixDef.shape = new box2d.b2PolygonShape();
var vertices = []
vertices.push(new box2d.b2Vec2(30/SCALE, 0/SCALE));
vertices.push(new box2d.b2Vec2(14/SCALE, 0/SCALE));
vertices.push(new box2d.b2Vec2(17/SCALE, 10/SCALE));
vertices.push(new box2d.b2Vec2(17/SCALE, 100/SCALE));
vertices.push(new box2d.b2Vec2(0/SCALE, 290/SCALE));
vertices.push(new box2d.b2Vec2(12/SCALE, 300/SCALE));
vertices.push(new box2d.b2Vec2(32/SCALE, 300/SCALE));
vertices.push(new box2d.b2Vec2(44/SCALE, 290/SCALE));
vertices.push(new box2d.b2Vec2(27/SCALE, 100/SCALE));
vertices.push(new box2d.b2Vec2(27/SCALE, 10/SCALE));
fixDef.shape.SetAsVector(vertices, 10);
bodyDef.position.x = 600 / SCALE;
bodyDef.position.y = 300 / SCALE;
this.view.body =  world.CreateBody(bodyDef);
this.view.body.CreateFixture(fixDef);

有人知道这件事吗?谢谢。

方法SetAsVector需要一个凸多边形。但我认为你们试图在这里设置的是一个凹面

较新版本的Box2D支持从凹多边形生成凸多边形,但我认为Box2DWeb不支持这一点

可以通过将凹多边形拆分为两个凸多边形并创建两个固定装置(而不是一个)来解决此问题