How can I interact with an object in box2d, I'm completely new to this so I have no clue what to do. The box is created like this:

bodyDef.type = b2Body.b2_dynamicBody;
fixDef.shape = new b2PolygonShape;

fixDef.shape.SetAsBox(0.5, 0.5); // Half-Width, Half-Height

bodyDef.position.x =  5;
bodyDef.position.y =  5;

How can I change the x, y positions of that box, tried bodyDef.position.x--; but it returned "bodyDef is not defined". How do I access this?


1 Answer 1


For moving here is SetTransform, for interacting MouseJoint. BodyDef is used to make creation of bodies easier, so it is used just in that function, you have to store value returned by CreateBody, and read documentation first.

  • \$\begingroup\$ Yeah I've looked trough the docs but there is no search function so it's kind of messy. Also I only started using this 10 hours ago, with 4-5 hours playing around and reading code. So basically I would do something like "player.SetTransform.position.x--;" if i store the value inside a player object? \$\endgroup\$ Commented Jul 22, 2012 at 8:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .