# Need HELP understanding DeltaTime

if my function Update() is updating at 60 FPS

update: function (dt) {
println(“car is running”);
println(frameCount);
}

does this mean that the time it takes for one frame to get to the next frame is approximately 0.16 sec?
or in other words, the time it takes the update function to run from the top to the bottom is approximately 0.16 seconds before it starts at the top again at 0 seconds and starts the next loop?

if dt = currentFrame - previousFrame does this mean that if the first frame(previousFrame) starts at 0.0 seconds and the start of the second frame(currentFrame) is 0.16
dt would = 0.16?
and the third frame would be 0.32 or 0.16 again?

that is,
frame 1: dt = 0.16
frame 2: dt = 0.16
frame 3: dt = 0.16
frame 4: dt = 0.16
…and so on

or does it mean

frame 1: dt = 0.16
frame 2: dt = 0.32
frame 3: dt = 0.48
frame 4: dt = 0.64
…and so on

in addition, what would something like jumpCounter -=dt mean?

thank you.
been having a really hard time trying to understand this. I hope the answer helps others

Here is how `dt` is calculated:

``````var now = pc.now(); // current ms
var ms = now - (this._time || now); // elapsed since last tick
var dt = ms / 1000.0; // divide by 1000 (ms in sec)
this._time = now; // remember last time
dt = pc.math.clamp(dt, 0, 0.1); // limit dt to lowest of 10fps
``````

So your `dt` will not accumulate, but every frame will represent how long it has elapsed since last tick as % of a second.
This value will be quiet low, and if you actually summarise it each frame, then every second it will increment by total of 1.0.
So it can be treated as % of a second it took last frame to update + render.

This becomes very easy, if you want to do speeds in second. For example you want to turn entity by 360 degrees in a second, then you write:

``````this.entity.rotate(0, 360 * dt, 0);
``````

Or lets say you want to move forward 50 km/h. And world units are in meters, meaning you want to move 50/1000 (in meters), forward (-1 in z). So dt - is % of a second, multiply by 60sec (in a minute) and then again by 60min (in a hour), you get speeds in km/h, and it will be independent from fps which is what you want:

``````var kmh = 50.0;
this.entity.translate(0, 0, -(kmh / 1000) * dt * 60 * 60);
``````

Experimentation, and playing with it, helps to understand it.
Use `console.log` and browser dev tools and console to output some values, and inspect them, so your question about frames would be answered by little experiment with console.

1 Like

Ok I understand better now. I came up with this. 0.16(dt) * 60 = 1.0 or 1/60
In other words, how many times our update function is updating per second (how fast is our code inside our update function running per second) in this case 60 times per second. great for moving in seconds.
made enough sense for me this way.

thank you