Box2dWeb机构没有发生碰撞

时间:2015-06-07 14:53:38

标签: node.js box2dweb

我已将Box2dWeb实施到Node.js服务器中,除碰撞外,一切正常。当有2名球员连接时,他们的身体不会碰撞 - 只是互相通过。这是玩家身体创建代码:

//World creation
var world = new b2World(new b2Vec2(0, 0));
//Body+Fixture creation
var bodyDef = new b2BodyDef();
bodyDef.type = b2Body.b2_dynamicBody;
bodyDef.position.x = 100;
bodyDef.position.y = 100;
bodyDef.linearDamping = 5;
bodyDef.angularDamping = 1;

var fixDef = new b2FixtureDef();
fixDef.density = 0.001;
fixDef.friction = 1;
fixDef.restitution = 1;
fixDef.shape = new b2CircleShape;
fixDef.shape.SetRadius(8);

var body = world.CreateBody(bodyDef);
body.CreateFixture(fixDef);

非常感谢任何帮助!

编辑:我已添加此代码:

var listener = new Box2D.Dynamics.b2ContactListener;
listener.BeginContact = function(contact) {
    console.log(contact.GetFixtureA().GetBody().GetUserData());
}
world.SetContactListener(listener);

一旦身体发生碰撞,我得到" null"在控制台中。

1 个答案:

答案 0 :(得分:0)

好的,这很简单,就像我预期的那样。我改变了代码:

this.world.Step(deltaTime);

this.world.Step(deltaTime, 10, 10);