Using time.deltaTime

I’ve been wondering… Is it really necessary to use time.deltaTime when thrusting? I mean we’re using physics (rigidbody) and as far as I know, the very fact that we’re dealing with physics, makes our game frame independent, but I might be wrong.

I think Rick makes a few compromises in his code for the sake of simplicity. If I remember correctly, the thrusting in Project Boost was done using the AddForce() method of the rigidbody, which turns internally the unity units into Newtons (force units) and is thus already frame rate independent like you said.

However, manipulating the rigidbody should be done in FixedUpdate() and thus Time.fixedDeltaTime should also be used. Manipulating rigidbodies in Update() can lead to problems, albeit in such a small game is mostly fine.

On another note, manipulating the velocity of rigidbody directly is also directly frame rate independent. However, using MovePosition() or MoveRotation() with a kinematic rigidbody does need to be modified with Time.fixedDeltaTime.

I have 2 rules of thumb or this if I can’t remember quite right. First, look into the documentation. If in the scripting documentation there isn’t any sign of Time.deltaTime most probably the method doesn’t need it. Second, if you apply it in code anyways and find that you need to increase your speed modifier by a huge amount in order for the object to move (like 500, 1000, 2000 or more) then most probably Unity is internally making it already frame rate independent and you don’t need the Time.(fixed)deltaTime modifier.

4 Likes

Thank you for your explanation!

1 Like

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

Privacy & Terms