I want to use a Mouse Joint in a similar way to the testbed so that I can grab and throw objects around the screen. However, currently, the objects snap to the mouse at the center of the object. So if I pull on a corner, it still snaps to the center of the box.
Here's my code currently (AS3):
Any help would be great.
Here's my code currently (AS3):
Code:
public function MouseDown(evt:MouseEvent){
var md:b2MouseJointDef = new b2MouseJointDef();d
md.body1 = m_world.GetGroundBody();
md.body2 = GetBodyAtMouse();
md.target.Set(md.body2.GetPosition().x+camera.x*2/30,md.body2.GetPosition().y+camera.y*2/30);
md.timeStep = 1/30;
md.maxForce = 300000*Spirit.GetMass();
SpiritGrabJoint = m_world.CreateJoint(md) as b2MouseJoint;
}
public function MouseMove(evt:MouseEvent){
XMouse = evt.stageX;
YMouse = evt.stageY;
if(SpiritGrabJoint!=null)SpiritGrabJoint.SetTarget(new b2Vec2((XMouse/30), (YMouse/30)));
}
public function destroyGrabJoint(){
m_world.DestroyJoint(SpiritGrabJoint);
SpiritGrabJoint = null;
}
var md:b2MouseJointDef = new b2MouseJointDef();d
md.body1 = m_world.GetGroundBody();
md.body2 = GetBodyAtMouse();
md.target.Set(md.body2.GetPosition().x+camera.x*2/30,md.body2.GetPosition().y+camera.y*2/30);
md.timeStep = 1/30;
md.maxForce = 300000*Spirit.GetMass();
SpiritGrabJoint = m_world.CreateJoint(md) as b2MouseJoint;
}
public function MouseMove(evt:MouseEvent){
XMouse = evt.stageX;
YMouse = evt.stageY;
if(SpiritGrabJoint!=null)SpiritGrabJoint.SetTarget(new b2Vec2((XMouse/30), (YMouse/30)));
}
public function destroyGrabJoint(){
m_world.DestroyJoint(SpiritGrabJoint);
SpiritGrabJoint = null;
}
Any help would be great.