What is deltaTime measured in on Roblox?

What is deltaTime measured in on Roblox? I am assuming milliseconds but I might be wrong, as it could be seconds.

I tried looking into documentation and even on DevForum, but couldn’t find a single answer regarding this.

I think it is seconds, not milliseconds. I remember reading something about that not too long ago so I am 75% sure it’s seconds.

2 Likes

It does say in the official documentation in at least two places, but it was hidden first in an example and second in the BindToRenderStep documentation where there’s of course no guarantee that the statement applies to all of the other events.

You could also test this yourself quite easily.

2 Likes

I just wanted to ask, what is delta time? It never made sense to me.

Delta time is the exact amount of time elapsed between events, with as much precision as possible.

Computers aren’t perfect and things like task.wait(1) and even fancier things like RenderStepped and Heartbeat can’t be guaranteed to run for an exact amount of time. task.wait(1) is guaranteed to wait for 1 or more seconds, and it will always be more. There are numerous reasons for this, software, hardware, and practical. Numeric incompatibilities (you specify one number but that number just can’t be reached because it isn’t divisible by the cycle speed of the computer or application), lag and general inconsistencies, the CPU getting distracted with something else for a few extra nanoseconds, etc.
In addition, things like task.wait and RenderStepped run on Roblox’s task scheduler, which specifies when things run. When does the engine calculate physics, when does the engine render the next frame, when do we check if any scripts that are currently using task.wait() are finished waiting and resume those scripts, etc. Things take variable amounts of time and they won’t line up perfectly where we want them.

So we use deltaTime and multiply it by something to make that something become ‘per second’.
Suppose we were creating our own Tween library instead of using TweenService, just for fun. If you want a GUI to move across the screen at 100 pixels per second, you’d do something like this.

RenderStepped:Connect(function(deltaTime)
    pixelsToMove = 100 * deltaTime
    -- deltaTime for RenderStepped is approximately (but not exactly) 1/60.
    moveThings()
end)

This guarantees that despite any irregularities or lag, you move at an exact 100 pixels per second.

5 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.