## 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

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!

ivan
Party member
Posts: 1601
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

### Re: Physics object movement q

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

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

ivan
Party member
Posts: 1601
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

### Re: Physics object movement q

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

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

ivan
Party member
Posts: 1601
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

### Re: Physics object movement q

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

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

raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

### Re: Physics object movement q

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.

ivan
Party member
Posts: 1601
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

### Re: Physics object movement q

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

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

### Who is online

Users browsing this forum: Nixola and 25 guests