Page 1 of 3
Physics object movement q
Posted: Fri Sep 27, 2019 10:50 am
by Coder567
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!
Re: Physics object movement q
Posted: Fri Sep 27, 2019 12:32 pm
by ivan
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.
Re: Physics object movement q
Posted: Fri Sep 27, 2019 12:37 pm
by Coder567
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
Re: Physics object movement q
Posted: Fri Sep 27, 2019 12:48 pm
by ivan
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?
Re: Physics object movement q
Posted: Fri Sep 27, 2019 1:43 pm
by Coder567
I just need to know how much force to put on the ball so it reaches the target
Re: Physics object movement q
Posted: Fri Sep 27, 2019 2:22 pm
by ivan
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.
Re: Physics object movement q
Posted: Fri Sep 27, 2019 2:42 pm
by Coder567
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
Re: Physics object movement q
Posted: Fri Sep 27, 2019 6:16 pm
by raidho36
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.
Re: Physics object movement q
Posted: Sat Sep 28, 2019 5:07 am
by ivan
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.
Re: Physics object movement q
Posted: Sat Sep 28, 2019 8:28 am
by Coder567
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