Timer vs real time

Hi! Im use timer for offset my pawn every 0.01 sec. Offset variable is 1000 * 0.01 (timer delta time). But if i set timer interval to 0.1 sec, and set offset var to 1000 * 0.1, my pawn moves faster! Why timer executions does not coincide with the real speed of time?

With times lower then rendering time timers might not behave correctly, because if i’m not mistaken it check timers on per frame basis, timers is good if you use bigger time spans that don’t require precision.

You should use tick event for things like movement for max precision, remember that in real time games everything operates on frame per frame basis, so everything (you might find some exception specially if animation is played directly to rendering) that moves on world is operated by Tick event which executes on every frame cycle. It gives you delta time which is estimated time passed between frames. Anything you will multiply to that delta time will turn in to “value change/s” and value will change pricisly as much as engine allows.

If you want things to move in fixed intervals, you can also do with tick but it requires more math. divide delta time to interval and floor it so you got natural number, multiple delta value to it and apply it, subtract floored result of first calculation to delta time and keep result of that in varable and add it to delta time on next tick (in beginning of tick)

Note that in CPU there no sense of time aspecially when each CPU runs of different frequency and some even change that frequency on the go, you can only read time and make code behave accordingly to time passed, so real time in programming is just a illusion by extreme fast CPU execution times. Timers will only trigger when timer code is checking time, but there always a limit of how much timer clock can be checked and it’s always irregular check interval as OS will not run your code on CPU all the time, not to mention engine it self is also busy doing other things it can’t check time all the time. Thats why timers have limited precision and delta time is actually more precise time counting tool then timers it self.

Thanks for the expanded answer!