Page 1 of 1

need help in using mouseJoint:setTarget and physics gravity

Posted: Thu Feb 12, 2009 8:55 pm
by solarice
if I set gravity and mouseJoint:setTarget for body at one time it doesn't work together.
for example I set

Code: Select all

pl.body = love.physics.newBody(world, pos_x, pos_y)
love.physics.newCircleShape(pl.body, 28)
pl.body:setMassFromShapes()

pl.mouseJoint = love.physics.newMouseJoint(pl.body, pos_x, pos_y)
...

self.mouseJoint:setTarget(x_, y_)
then mouseJoint system is working, gravity - not.

if I set

Code: Select all

pl.body = love.physics.newBody(world, pos_x, pos_y)
love.physics.newCircleShape(pl.body, 28)
pl.mouseJoint = love.physics.newMouseJoint(pl.body, pos_x, pos_y)

pl.body:setMassFromShapes()
...

self.mouseJoint:setTarget(x_, y_)
gravity is working, no mouseJoint :( :( :(

Re: need help in using mouseJoint:setTarget and physics gravity

Posted: Thu Feb 12, 2009 9:29 pm
by osuf oboys
The issue isn't that one or the other does not work but that one of the two forces inolved is much stronger than the other, in effect rendering one negligible. A mouse joint is by default much more powerful than gravity, hence explaining the scenario if you set the mass before creating the joint. If you do not set the mass before creating the joint, the maximum force of the mouse joint will be initialized using the present mass as basis: 0, as though there were no mouse joint.

Try setting maxForce of the mouse joint to 0.01 times the gravity times the inertia of the body, after setMassFromShapes(). This should keep the two forces somewhat balanced, regardless of whether or not you place setMassFromShapes before or after you create the mouse joint.

Re: need help in using mouseJoint:setTarget and physics gravity

Posted: Thu Feb 12, 2009 10:23 pm
by solarice
thank u for reply, but seems it's bad idea :(
when i change the maxForce it's not effect on anything, as inertia. When i change the gravity, body became unstable and move down only when i help by clicking ( it starts the mouseJoint:setTarget(x_, y_)), bad move up and beside, it's going like for parabola :( i was trying dif gravities...