Download

How to make time it takes to increase movement speed framerate independent?

Hi,

i have an endless runner kind of game, based on the SideScrollerBP-Example. The “Event-Tick” is hooked up to an “Add Movement Input”- Node and the Scale-Value is set to “1” so that the runner runs by itself. Whenever someone presses the “RunRight”-key the speed of the runner is increased by 10.

67686da1ecba2f0024b2831ec7a52fe5125694f0.png

My problem now is that the time between pressing the key to increase the speed and the increasing of the speed is framerate dependent, cause the speed is only updated every frame (by calling “Add Movement Input” every frame). How can i now increase the speed at the exact same time independent of framerate? I tried a Timer that calls the “Add Movement Input” every 1ms, but this seems hacky (and i’m not really sure that this works correctly).

Rather than thinking by frame, think of it as an speed increase per second. Then you’ll want to divide that rate up over the frames within a second by multiplying it by the length of each frame in seconds. Which is what delta time is.

If you multiply your speed increases rate by the current delta time (there’s both a node for it and an output on the Tick event for it) then you’ll have a constant increase rate per second, regardless of the framerate.

Thanks for the answer!
It would get very complicated if someone pressed the key 10 times in a second (each at a different frame), cause then i would have to keep track of 10 different 1 sec windows.
But aside from that acceleration over a second isn’t really an option :(.
Is there really no way to update the speed between frames (by the time you press the key)?

Unreal does not play well with anything frame dependent. When we re-designed and ported SSP for Unreal from GM, we had to figure out a new way to handle things. You must think in terms of time, not frames.

Multiply by deltatime…