views:

371

answers:

2

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

Does it exist any way to drag a body instantaneously?

A: 

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.

Matt Montag
See my answer for the solution!
Ricibald
Thanks! Works perfectly. I found an example of mousejoint usage in Processing here: http://processing.org/discourse/yabb2/YaBB.pl?num=1213404906/30 and modified it with your suggestion.
Matt Montag
I can't vote up my own answer! Please vote it up so the answer appears on top!
Ricibald
I can't either. I need "15 reputation" or something.
Matt Montag
+1  A: 

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

related questions