Physics, forces and dt

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
Applepiesoda
Prole
Posts: 5
Joined: Wed Nov 16, 2022 2:33 pm

Physics, forces and dt

Post 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:
Attachments
Physics game test.love
(430.5 KiB) Downloaded 68 times
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Physics, forces and dt

Post by Bigfoot71 »

No there is no need, you can go to this page, it can help you: https://love2d.org/wiki/Tutorial:Physics
My avatar code for the curious :D V1, V2, V3.
Applepiesoda
Prole
Posts: 5
Joined: Wed Nov 16, 2022 2:33 pm

Re: Physics, forces and dt

Post 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:
User avatar
BrotSagtMist
Party member
Posts: 607
Joined: Fri Aug 06, 2021 10:30 pm

Re: Physics, forces and dt

Post 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.
obey
Applepiesoda
Prole
Posts: 5
Joined: Wed Nov 16, 2022 2:33 pm

Re: Physics, forces and dt

Post 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! :)
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Physics, forces and dt

Post 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.
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: Physics, forces and dt

Post by pgimeno »

If you're trying to speed up time, why not apply that to world:update()?
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Physics, forces and dt

Post 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.
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
Post Reply

Who is online

Users browsing this forum: targetcreature and 51 guests