javascriptbox2dweb

Get X and Y coordinates from collision in Box2dweb (JavaScript)


When there is a collision in Box2dweb, this class create some objects. b2ContactListener.prototype.BeginContact

From there I can access a lot of data with:

var a = contact.GetFixtureA().GetUserData();
var b = contact.GetFixtureB().GetUserData();

Yet I can't find the way to get the X and Y values of the collision with some seudo code like this.

var aColX = contact.GetFixtureA().GetBody().GetPosition().x;
var aColY = contact.GetFixtureA().GetBody().GetPosition().y;

What's the right way to get this data from contact.GetFixtureA()? //Object A


Solution

  • This is the answer.

    var aColX = contact.GetFixtureB().GetBody().GetTransform().position.x;
    var aColY = contact.GetFixtureB().GetBody().GetTransform().position.y;