2013-10-05 101 views
0

這裏的prolemBox2DWeb,PolygonShape.SetAsVector無法檢測碰撞

enter image description here

如果我定義與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); 

任何人都知道這是界定?謝謝。

回答

0

SetAsVector方法需要凸多邊形。但我認爲你在這裏設置的是一個凹陷的。

較新版本的Box2D支持從凹面生成凸多邊形,但我不認爲Box2DWeb支持此功能。

你可以通過將你的凹多邊形分成兩個凸多邊形並創建兩個夾具而不是一個來解決這個問題。

Wikipedia article about convex and concave polygons