need help in using mouseJoint:setTarget and physics gravity

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
solarice
Prole
Posts: 2
Joined: Thu Feb 12, 2009 8:47 pm

need help in using mouseJoint:setTarget and physics gravity

Post 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 :( :( :(
osuf oboys
Party member
Posts: 215
Joined: Sun Jan 18, 2009 8:03 pm

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

Post 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.
If I haven't written anything else, you may assume that my work is released under the LPC License - the LÖVE Community. See http://love2d.org/wiki/index.php?title=LPC_License.
solarice
Prole
Posts: 2
Joined: Thu Feb 12, 2009 8:47 pm

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

Post 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...
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 67 guests