I used search, and here I am
I use (for the time being) love.update(dt) function to run my custom physics. But it appears that "dt" in LOVE is not nearly a constant.
As far as my physics require precise delta-time setting (not ever-changing dt LOVE gives us) to run calculations, I have a question:
Is there ANY way to set my own constant delta-time?
As you may know, many dynamic physics calculations use Time. So I decided to use dt in my calculations, so I can update parameters in tiny instants of time, like 0.001 sec. But if you get delta-t values to change sporadically (difference between 0.001 and 0.002 is 100%!) all your math will collapse.
About setting custom "dt"
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: About setting custom "dt"
You cannot directly control the frame rate. But you can ignore the framerate
However, I don't recommend that.
Can you specify, what you mean by "all your math will collapse"?
Code: Select all
function love.update(dt)
dt = 1/60
[...]
end
Can you specify, what you mean by "all your math will collapse"?
Check out my blog on gamedev
Re: About setting custom "dt"
Basically he wants replays to be the same, so that if he does maths on whatever it won't be affected by using *dt.
i think? or maybe preventing large changes in delta time.
i think? or maybe preventing large changes in delta time.
Last edited by qaisjp on Wed May 29, 2013 3:56 pm, edited 1 time in total.
Lua is not an acronym.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: About setting custom "dt"
What you can do is this:
Code: Select all
function love.load()
time_left = 0
epsilon = 0.01 -- something suitably small, I dunno
-- do other stuff
end
function love.update(dt)
time_left = time_left + dt
while time_left > epsilon do
do_physics_update(epsilon)
time_left = time_left - epsilon
end
-- do other stuff
end
Help us help you: attach a .love.
Re: About setting custom "dt"
You can use custom-dts for Bullet Time! As long as everything is dependent on DT you can do this:
or
Code: Select all
dt = dt/2 --Slows it down
Code: Select all
dt = dt*2 --Speeds it up
PM me on here or elsewhere if you'd like to discuss porting your game to Nintendo Switch via mazette!
personal page and a raycaster
personal page and a raycaster
- misterspok
- Prole
- Posts: 20
- Joined: Fri Apr 19, 2013 12:40 pm
Re: About setting custom "dt"
Sure I can. Delta-V, that is calculated for the spacecraft, depends on propellant mass loss that craft uses to bun. Basically, it is the Tsiolkovsky's equation. To calculate maximum mass loss for given engine thrust I need delta-time (dt). So, as you can see, if dt varies between, say, 0.001 and 0.002, it means that during burn time engine thrust will sporadically increase/decrease TWICE the value.micha wrote:Can you specify, what you mean by "all your math will collapse"?
If you add here a gravitational influence, to calculate how it changes the vertical speed of the craft you also need dt.
Sure, I can stop using dt, but how will I make physics calculations to correspond to what is going on on the screen then?
Yes, Robin, I see your point. Some elegant solution here But will it not lay an unwanted crapload of math on CPU, and thus continously drop framerate?Robin wrote:What you can do is this:
...
Ignore the frame rate? That is interesting. But why would you not recommend that? I must try it and seemicha wrote:You cannot directly control the frame rate. But you can ignore the framerateHowever, I don't recommend that.Code: Select all
function love.update(dt) dt = 1/60 [...] end
Edit Nope, the more the difference between dt I set and real dt, the more faulty math gets. Maybe I should forfeit the use of love.update function?
Re: About setting custom "dt"
If you don't use love.update what can you use...?
Lua is not an acronym.
Re: About setting custom "dt"
Robin's solution is excellent. It's not that demanding on the CPU either. I'm not sure there can exist a better solution than that. Attempting to freeze the framerate is a significantly worse solution as it would slow down gameplay if the computer isn't fast enough (whereas Robin's solution simply makes the game laggier, not slower, and keeps the correct physics simulation).
I'm also curious why you would need to repeat the same simulation twice with exactly identical results.
I'm also curious why you would need to repeat the same simulation twice with exactly identical results.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
- misterspok
- Prole
- Posts: 20
- Joined: Fri Apr 19, 2013 12:40 pm
Re: About setting custom "dt"
Well, the result is not identical! The timescale required to be identical. The result you get is continously updated vertical and horizontal velosities (pardon me, radial and tangential would be more accurate), altitude and distance. Also, during the burn, propellant mass will decrease, causing reactive acceleration to increase. That is why I need to repeat the same simulation continously, if I understood your question right.T-Bone wrote:I'm also curious why you would need to repeat the same simulation twice with exactly identical results.
Though I will try Robin's solution and report here as soon as I can.
Edit: Well, Robin's solution seem to work damn fine to me I got some legit results now. Now I just regret that I don't have enough programming skill yet to figure it out by myself Thank you.
- OmarShehata
- Party member
- Posts: 259
- Joined: Tue May 29, 2012 6:46 pm
- Location: Egypt
- Contact:
Re: About setting custom "dt"
That's actually a pretty important thing, and it's why Box2d was written to be deterministic.T-Bone wrote: I'm also curious why you would need to repeat the same simulation twice with exactly identical results.
(pulled from the Box2d FAQ)
There's a lot of reasons to want the same input to give you the same output. Imagine you're designing a puzzle game. You've hand crafted an elaborate solution. Now the worst thing would be if the player could solve it just by repeating the same thing enough times until it happens to work. Besides, you usually want the simulation to play out for every player the way you designed it, so it wouldn't go off in any erroneous way.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests