Physics object movement q

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Coder567
Prole
Posts: 42
Joined: Sun Apr 07, 2019 12:32 pm

Physics object movement q

Post by Coder567 » Fri Sep 27, 2019 10:50 am

Hi
I'm using the physics library but my problem is I don't know how long it takes for the object to move to it's destination. Does anyone know the formula for this?

If I have friction 0.25 then how much force I need to apply to the ball so it has traveled 300 pixels in two seconds?

Code: Select all

ball.body:setLinearDamping( 0.25 )
ball.body:applyForce(-400, 0) -- How much force to apply?
I don't know if this is somehow effect by love.physics.setMeter(64)

thanks!

User avatar
ivan
Party member
Posts: 1520
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Physics object movement q

Post by ivan » Fri Sep 27, 2019 12:32 pm

Does anyone know the formula for this
time = distance/speed
The problem is that the rigid bodies in love.physics do not move with a constant speed especially when collisions and damping are involved.
Like I said in my previous post, you need to find a better way to move your bodies, such as a mouse joint, applyForce or applyImpulse.

Coder567
Prole
Posts: 42
Joined: Sun Apr 07, 2019 12:32 pm

Re: Physics object movement q

Post by Coder567 » Fri Sep 27, 2019 12:37 pm

ivan wrote:
Fri Sep 27, 2019 12:32 pm
Does anyone know the formula for this
time = distance/speed
Thanks I got the time formula but that was not my question
ivan wrote:
Fri Sep 27, 2019 12:32 pm
The problem is that the rigid bodies in love.physics do not move with a constant speed especially when collisions and damping are involved.
Yes but I only need to know straight movement
ivan wrote:
Fri Sep 27, 2019 12:32 pm
Like I said in my previous post, you need to find a better way to move your bodies, such as a mouse joint, applyForce or applyImpulse.
I'm using applyForce

User avatar
ivan
Party member
Posts: 1520
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Physics object movement q

Post by ivan » Fri Sep 27, 2019 12:48 pm

The "direction" of the movement is irrelevant.
If you have damping and friction then the body is not moving at a "constant speed".
Why do you need to estimate the time of arrival?

Coder567
Prole
Posts: 42
Joined: Sun Apr 07, 2019 12:32 pm

Re: Physics object movement q

Post by Coder567 » Fri Sep 27, 2019 1:43 pm

I just need to know how much force to put on the ball so it reaches the target

User avatar
ivan
Party member
Posts: 1520
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Physics object movement q

Post by ivan » Fri Sep 27, 2019 2:22 pm

You don't need to know the time - but it would help if you knew the distance to target.
Just keep applying the force until the ball is "close enough" to the target.
Mouse joints are usually the better option.

Coder567
Prole
Posts: 42
Joined: Sun Apr 07, 2019 12:32 pm

Re: Physics object movement q

Post by Coder567 » Fri Sep 27, 2019 2:42 pm

The slow down effect of the ball would be nice, not just applying more force

And I can get distance to target, no problem there

User avatar
raidho36
Party member
Posts: 1919
Joined: Mon Jun 17, 2013 12:00 pm

Re: Physics object movement q

Post by raidho36 » Fri Sep 27, 2019 6:16 pm

How much force to apply depends on how much acceleration you want and how much does the object weighs.

F = m / a

Damping simply applies a force like this but in direction opposite to motion direction. Assuming that direction vs force angle mismatch isn't very important, you can simply increase desired acceleration by this value in the above formula. You will get a force that fully counteracts damping and then provides desired acceleration.

User avatar
ivan
Party member
Posts: 1520
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Physics object movement q

Post by ivan » Sat Sep 28, 2019 5:07 am

The slow down effect of the ball would be nice, not just applying more force
Your body already has damping so it should "ease" to a stop by itself.
One hacky approach could be to make the force proportional to the distance:
force = min(easing/distance, 1) * force
where "easing" is the distance you want the object to slow down.
You may have to adjusting the damping too.

Coder567
Prole
Posts: 42
Joined: Sun Apr 07, 2019 12:32 pm

Re: Physics object movement q

Post by Coder567 » Sat Sep 28, 2019 8:28 am

raidho36 wrote:
Fri Sep 27, 2019 6:16 pm
How much force to apply depends on how much acceleration you want and how much does the object weighs.

F = m / a

Damping simply applies a force like this but in direction opposite to motion direction. Assuming that direction vs force angle mismatch isn't very important, you can simply increase desired acceleration by this value in the above formula. You will get a force that fully counteracts damping and then provides desired acceleration.
I'm not very good at math. I tried

Code: Select all

f = ball.body:getMass() / testTravelDist
where testTravelDist is the distance I want the ball to move but with that it doesn't move at all

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests