Page 1 of 1

Physics, forces and dt

Posted: Wed Nov 16, 2022 3:05 pm
by Applepiesoda
Hello, all you awesome people! :awesome:

I am currently developing a fast-paced run-and-gun game, and I have run into a physics problem. (I might not implement physics later, this is still in a very early stage of development :) )

But onto the question at hand. I am using the windfield library, which I think is great atm. I also navigated many videos and forum posts to learn how to move my player using the physics library. The different methods I have found are applyForce, applyLinearImpulse, setLinearVelocity, and setX + some speed?. So I decided to try applyForce first, and when I tried it, it works. However, when I multiply my speed variable with dt, it slows to a crawl, and I have to use way bigger numbers to get it to move.

So this got me thinking, do physics calculations not need dt, or does it get multiplied with dt when the world gets updated (world:update(dt))? And is applyForce the best thing to use for this situation, or are there better ways?

I included my (kinda barebones) .love file if you wanna take a look. Also, this is my first post, so please tell me if I have done something wrong or if you need help understanding something! :nyu:

Re: Physics, forces and dt

Posted: Mon Nov 21, 2022 9:00 pm
by Bigfoot71
No there is no need, you can go to this page, it can help you: https://love2d.org/wiki/Tutorial:Physics

Re: Physics, forces and dt

Posted: Mon Nov 21, 2022 9:59 pm
by Applepiesoda
Thanks a bunch for getting me on the right track! :ultraglee:

I took a look at that tutorial before, and saw that they did not multiply the force with dt. But I wanted to be extra certain so that I didn't dig my own grave here :? But the other tutorials I found mostly worked with Impulses, not Forces, and they did not mention dt. So I wanted some extra help!

Thanks again! I will experiment to my heart's content now :awesome:

Re: Physics, forces and dt

Posted: Mon Nov 21, 2022 11:17 pm
by BrotSagtMist
But dt being a time span, multiplying forces over a time span is not exactly sensible.
Its applying forces over a span, and giving the span to the simulation step does that for you.

Re: Physics, forces and dt

Posted: Tue Nov 22, 2022 4:32 pm
by Applepiesoda
BrotSagtMist wrote: Mon Nov 21, 2022 11:17 pm But dt being a time span, multiplying forces over a time span is not exactly sensible.
Its applying forces over a span, and giving the span to the simulation step does that for you.
Ah, I see... I have mostly just worked with changing X and Y values of an object (where I multiplied by dt), and not that much with physics. But when you put it like that it makes total sense (multiplying forces over a time span sounds pretty weird, I agree :rofl: ). Thank you! :)

Re: Physics, forces and dt

Posted: Sun Oct 08, 2023 1:36 am
by togFox
Sorry for resurrecting this thread - I think it is relevant as I'm having force and dt issues as well.

I have large and heavy physical objects (battleship) that has a large mass but a large force and I have the Box2D simulating slow acceleration curve and all that is fine. I use this code:

Code: Select all

physobj.body:applyForce(math.cos(currentangle) * obj.currentforce, math.sin(currentangle) * obj.currentforce)
obj.currentforce is the force being applied. This works well until I implement some sort of time acceleration. I have a global value: TIME.

The line above doesn't move my object any faster (because it's the same force) however, this line also causes problems:

Code: Select all

physobj.body:applyForce(math.cos(currentangle) * obj.currentforce * TIME, math.sin(currentangle) * obj.currentforce * TIME)
The object speeds up so that's good - but the phyiscal rules around momentum and inertia still apply so the acceleration does not speed up. Unless I can make it accelerate and decelerate with respect to TIME my sim sill be inconsistent.

I suspect Body:setLinearVelocity( x, y ) will fix my problem but I was hoping to get the "feel" of inertia and momentum using applyForce but is there a way to make that TIME sensitive? Thanks.

Re: Physics, forces and dt

Posted: Sun Oct 08, 2023 6:06 am
by pgimeno
If you're trying to speed up time, why not apply that to world:update()?

Re: Physics, forces and dt

Posted: Sun Oct 08, 2023 8:26 pm
by togFox
I guess so. I also manipulate dt in other places of the game loop so will have to be careful to keep them synced. Could get messy but manageable.

Thanks.