Search code examples
mousedragdelaybox2d

Box2d: mousejoint without inertial delay


I'm using mousejoint to drag bodies in box2d, but it causes inertial delay.

Does it exist any way to drag a body instantaneously?


Solution

  • The solution is to tune up properties frequencyHz and dampingRatio in your b2MouseJointDef.

    For example:

    b2MouseJointDef md;
    md.body1 = _groundBody;
    md.body2 = body;
    md.target = p;
    md.maxForce = 10000.0f * body->GetMass();
    md.dampingRatio = 0;
    md.frequencyHz = 100;
    _world->CreateJoint(&md);