Question

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

Does it exist any way to drag a body instantaneously?

Was it helpful?

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);

OTHER TIPS

I'm trying to implement a pong-style game in Processing/Box2d library and I anticipate having the same problem. One thing that comes to mind is to maintain a hidden object in the Box2d world, one that operates with joints the conventional way, and then draw a virtual object that follows the mouse with no frame delay. This might be adequate to fool the user.

On the other hand, Box2d is not a strict physics simulation and allows for some forgiveness in overlapping objects, so it really seems like there should be a way to do this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top