I've implemented Box2dWeb into a Node.js server and everything works fine apart from collisions. When there are 2 players connected their bodies don't collide - just go through each other. Here's the player body creation code:
//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);
Any help is very much appreciated!
EDIT: I've added this code:
var listener = new Box2D.Dynamics.b2ContactListener;
listener.BeginContact = function(contact) {
console.log(contact.GetFixtureA().GetBody().GetUserData());
}
world.SetContactListener(listener);
and once the bodies collide, I get "null" in the console.
OK, that was simple, just as I expected it would be. I changed the code from:
to