delta time vs fps

zampa

Member
So i am working with delta time for movement and i had a question

GML:
hmovement = ((hspd * move_spd * speed_mod) + knockback_x) * delta;   

vmovement = ((vspd * move_spd * speed_mod) + knockback_y) * delta;
this is my movement code

Code:
delta = (delta_time/1000000) * 60;
and this is how i set delta

but i found out that delta varies a lot from frame to frame
ex:
0.94
1.00
1.04
0.98
1.02

rounding delta is not an option

so i thought to do it this way
Code:
delta = 60/fps;
because the value is way more stable

i mean it works i just wanted to know if this is a good way to do it
or could this create some problems am i not seeing right now

thanks
 

O.Stogden

Member
The "delta" variable shouldn't be touched. It's varying because your framerate is varying. If it gets forced to 1, then you are eliminating all delta time from your game and are making the code useless.

If the delta is above 1, that means your FPS has gone below 60, if it's below 1, it means you FPS has gone above 60. It's making adjustments because your framerate isn't exactly 60 the whole time.
 

zampa

Member
The "delta" variable shouldn't be touched. It's varying because your framerate is varying. If it gets forced to 1, then you are eliminating all delta time from your game and are making the code useless.

If the delta is above 1, that means your FPS has gone below 60, if it's below 1, it means you FPS has gone above 60. It's making adjustments because your framerate isn't exactly 60 the whole time.
yes i know, and agree that i should't touch delta, but should i calculate delta with 60/fps (target_fps/fps)?
 

O.Stogden

Member
I don't know how often the "fps" variable updates in Game Maker? If you draw it, it doesn't seem to update constantly.

I would assume doing
Code:
delta = (delta_time/1000000) * 60;
is more accurate than
Code:
delta = 60/fps;
It's more a case of why you would use the latter over the former? It's less accurate. Being stable isn't really a concern here, it would be if the value was changing from like 0.8 to 1.2 all the time, but changing from 0.96 to 1.04 on occasion is probably unnoticeable for a player.
 

zampa

Member
I don't know how often the "fps" variable updates in Game Maker? If you draw it, it doesn't seem to update constantly.

I would assume doing
Code:
delta = (delta_time/1000000) * 60;
is more accurate than
Code:
delta = 60/fps;
It's more a case of why you would use the latter over the former? It's less accurate. Being stable isn't really a concern here, it would be if the value was changing from like 0.8 to 1.2 all the time, but changing from 0.96 to 1.04 on occasion is probably unnoticeable for a player.
to avoid sub pixel movement subtract the fraction from hmovement and vmovement and add it back when it sums up to 1 with delta being inconsistant the movement is a bit jittery

Also i read about the fps variable on the doc and this is what it says

"This read-only variable returns the current fps as an integer value. Please note that the function will only update once every step of your game and so may appear to "jump" from one value to another, but this is quite normal."
 
Top