Hello, all you awesome people!
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!
Physics, forces and dt
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 5
- Joined: Wed Nov 16, 2022 2:33 pm
Physics, forces and dt
- Attachments
-
- Physics game test.love
- (430.5 KiB) Downloaded 90 times
Re: Physics, forces and dt
No there is no need, you can go to this page, it can help you: https://love2d.org/wiki/Tutorial:Physics
-
- Prole
- Posts: 5
- Joined: Wed Nov 16, 2022 2:33 pm
Re: Physics, forces and dt
Thanks a bunch for getting me on the right track!
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
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
- BrotSagtMist
- Party member
- Posts: 661
- Joined: Fri Aug 06, 2021 10:30 pm
Re: Physics, forces and dt
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.
Its applying forces over a span, and giving the span to the simulation step does that for you.
obey
-
- Prole
- Posts: 5
- Joined: Wed Nov 16, 2022 2:33 pm
Re: Physics, forces and dt
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 ). Thank you!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.
Re: Physics, forces and dt
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:
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:
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.
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)
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)
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.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
Re: Physics, forces and dt
If you're trying to speed up time, why not apply that to world:update()?
Re: Physics, forces and dt
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.
Thanks.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/idle-gridiron
Who is online
Users browsing this forum: Semrush [Bot] and 4 guests