Delta time is wrong (SOLVED)

Wikipedia: “Delta Time or Delta Timing is a concept used amongst programmers in relation to hardware and network responsiveness. In graphics programming, the term is usually used for variably updating scenery based on the elapsed time since the game last updated (i.e. the previous “frame”) which will vary depending on the speed of the computer, and how much work needs to be done in the game at any given time.”

Defold- examples: “Increase the elapsed time with dt, the delta time elapsed since last call to update().”

If that is true then you could make a script like this:

local f = gui.get_node("FPS")
gui.set_text(f,"FPS : " .. math.floor(1 / dt + 0.5))

but it never changes because the dt is exactly 1/60 <- 60 is the given framrate
Insted you have to make something like this for it to work:

local deltatime = os.clock() - self.time
self.time = os.clock()

local f = gui.get_node("FPS")
gui.set_text(f,"FPS : " .. math.floor(1 / deltatime + 0.5))

Can someone fix this or tell me if I have understood something wrong.

There’s a variable_dt option in game.project. If the value is unchecked the dt will always be 1/60, not matter how fast or slow your frames are. If the variable_dt is checked the dt value passed to update will reflect actual frame time and a frame that takes longer to complete will have a dt larger than 1/60.

1 Like

Note that the above description by @britzl applies to variable dt setting.
Otherwise (if variable dt is unchecked), the delta time will have the constant value of 1/60 (assuming 60 fps is set in game.project fps setting).

2 Likes

Oh, yes, I got that mixed up. Will update my answer. Thanks for pointing that out.

1 Like