Time.deltaTime - Complete C# Unity Game Developer 3D

In lesson 26 of the Complete C# Unity Game Developer 3D course we learned to make a rotating object. Does it makes sense to multiply the rotation speed by Time.deltaTime, similar to how we coded player movement speed to compensate for fps variation among pcs? It wasn’t mentioned in the course, but I figured since it is a moving object this compensation might be necessary. If not, then what situation do you multiply movement by Time.deltaTime?

Player movement:

vs rotation speed of object:

Hi Wesley,

Welcome to our community! :slight_smile:

You are right. To make the movement and rotation framerate-independent, we have to multiply the value(s) by Time.deltaTime. Bear in mind, though, that this is true only if we manipulate the Transform object as in your code.

When using the Rigidbody, we must not multiply by Time.deltaTime because the Rigidbody is controlled by the physics simulation, which takes care of the framerate-independence. I’m mentioning this because Rick uses the Rigidbody in the Project Boost section to move and rotate the player.

I hope this helped. :slight_smile:


See also:

2 Likes

well, I learned something new from just passing by

Good to know and thanks for the info! However, in section 3 titled project boost we are instructed to use Time.deltaTime on the rigidbody of the rocket.

The Rigidbody component handles frame-rate independence internally when using its built-in methods like setting velocity or applying forces, so typically you do not need to multiply by Time.fixedDeltaTime unless you are doing custom calculations that need to account for the fixed time step explicitly.

There is also different functions that you should be aware of:

Fixed Update

  • Use FixedUpdate for any physics-related updates.
  • Inside FixedUpdate , Unity’s physics system operates at a fixed time step, so you usually don’t need to manually account for delta time when applying forces or setting velocities directly on a Rigidbody.

Time.fixedDeltaTime

  • Use Time.fixedDeltaTime is if you need to perform custom calculations that are time-dependent inside FixedUpdate .
  • Example: You might use Time.fixedDeltaTime if you are a value over time.

Then there is Time.DeltaTime

  • Time.deltaTime is used in Update or LateUpdate for frame-rate independent behavior in non-physics calculations.
  • When modifying transform properties directly (e.g., transform.position ), you should use Time.deltaTime to ensure frame-rate independence.

So depending on your use case, there are different functions for your case.

2 Likes

Thanks for the detailed explanation and resources. This really helps!

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

Privacy & Terms