Hi,
i'm making a game in UE4 only with blueprints currently and i'm really unsure about variable frame rates and time.
So how do games handle variable frame rates?
Let's say i have an endless runner game. It runs on 2 different computers.
On computer A it runs with 100fps (10ms till next frame).
On computer B it runs with 1fps (1s till next frame).
The runner now runs with a speed of 10.
To make it frame rate independent i multiply the speed with the time since the last frame aka delta seconds - cool!
I now have 2 problems:
Problem 1:
0.997 seconds after the game has started the user presses a key that increases the speed of the runner by 5:
On second 1.000 the next frame arrives in both cases:
Comp A (100fps): 0.01*15
Comp B (1fps): 1.00*15
Comp B has now an advantage cause the new speed gets multiplied by 1 no matter when the key was pressed.
Solution: Keys are polled outside of the game loop thus record the time of the key press and then multiply according (0.997*10 + 0.003*15 in 2nd case).
Another problem is that Comp A will be ahead of Comp B most of the time cause of the much faster frame rate (cause A jumps every 10ms and B only every 1000ms), but this is a problem of variable frame rate/delta seconds itself.
Problem 2:
There are turbo fields on the ground, when you run over them your speed is increased by 5 for 3 seconds.
Both run over them at 0.097 seconds after the game started.
Comp A (100fps): Turbo-Effect will be activated 0.100 seconds in
Comp B (1fps): Turbo-Effect will be activated 1 seconds in
How do games handle the time difference here or do they handle it all?
Only solution i can think of is to add a delay so that the effect only happens after total delta time >1 second (ofc. that would still "break" if < 1fps).
To stop the effect after 3 seconds i would add the delta time since start of the effect and if total delta time > 3 i would solve it like in problem one.
Thanks for any answers/suggestions