If I create a body and join it to a b2MouseJoint, it tracks with the mouse just fine. However, if I change the body's position at any time, this value becomes an offset which throws off my mouse joint. However far I move it from (0, 0) is the same distance it stays from my mouse cursor.
Am I doing this wrong, or is this a bug in Box2DFlashAS3 2.1a?
Here is the code which creates the joint:
Here is the code which updates the position when dragging:
And here is an example of setting the position (this would cause the object to be 100 pixels away from the mouse):
Thank you in advance!
Am I doing this wrong, or is this a bug in Box2DFlashAS3 2.1a?
Here is the code which creates the joint:
Code:
var jointDefinition:b2MouseJointDef = new b2MouseJointDef ();
jointDefinition.bodyA = Physics.GetGroundBody ();
jointDefinition.bodyB = currentBody;
jointDefinition.maxForce = 300.0 * currentBody.GetMass ();
mouseJoint = Physics.CreateJoint (jointDefinition) as b2MouseJoint;
currentBody.SetAwake (true);
jointDefinition.bodyA = Physics.GetGroundBody ();
jointDefinition.bodyB = currentBody;
jointDefinition.maxForce = 300.0 * currentBody.GetMass ();
mouseJoint = Physics.CreateJoint (jointDefinition) as b2MouseJoint;
currentBody.SetAwake (true);
Here is the code which updates the position when dragging:
Code:
mouseJoint.SetTarget (new b2Vec2 (mouseX * PHYSICS_SCALE, mouseY * PHYSICS_SCALE));
And here is an example of setting the position (this would cause the object to be 100 pixels away from the mouse):
Code:
currentBody.SetPosition (new b2Vec2 (0, 100));
Thank you in advance!