What is Unity Time.DeltaTime? What Is It Used For?


One of the commands we see most often in Unity is the Time.DeltaTime command. So, let's talk about what this command does together.

What is Time.DeltaTime?

If you have read my previous post about Simple Functions in Unity, we talked about the difference between FixedUpdate and Update there. FixedUpdate was running equally on all systems, but Update could run more or less depending on the system power.
Now, let's get to the relevance of this explanation to DeltaTime.

Especially in Unity, in things like character and bullet movements, we use the Time.DeltaTime command, which ensures that the part we use works like FixedUpdate. Even if the system experiences freezing or lag, it ensures that the character always moves at the same rate.

To open up the working logic a bit more, we can explain it like this.

On a system running at 30 FPS, with Time.DeltaTime, character movement in the game will work as 1/30 = 0.33
On a system running at 15 FPS, with Time.DeltaTime, character movement in the game will work as 0.66.
More precisely, when the Update function reads Time.DeltaTime, the values it receives change, and it adapts according to the FPS value of the system, thus providing more optimal movement for the character or any movement.

To summarize the text above, we can think of the Time.DeltaTime value as a float variable that automatically takes a value based on our in-game FPS speed.

What Is Time.DeltaTime Used For?

With Time.DeltaTime, we move our character; in other words, we ensure it always travels at the same speed.
The general usage area of Time.DeltaTime is to move characters or objects like bullets.
When doing operations that may be affected by system speed, we generally multiply by Time.DeltaTime and ensure that it always remains equal.