Do I need deltaTime in FixedUpdate?

Hello!

I know that I have to use Time.deltaTime as multiplier in Update() and LateUpdate() to achieve frame rate independent movement.

Do I also need Time.deltaTime in FixedUpdate()? From my understanding the frequency this method is called is NOT dependent on frame rate so my guess is that I do NOT have to scale movement in FixedUpdate() with deltaTime.

To be more specific. This is my code:

private void FixedUpdate() {
   Vector3 objectVelocity = Vector3.back * 5.6f;    
   manipulatorObject.rb.velocity = objectVelocity;

Do I need to multiply objectVelocity by Time.deltaTime?

The fixed-update time is Time.fixedDeltaTime.

It’s not so much about where you call it but what operation you’re doing. If you’re doing an operation that should be scaled to be time-independent then you need to scale it by the appropriate time scaling fixed or non-fixed.

Setting the velocity to some literal (constant) value is already time-independent so scaling it by the elapsed fixed-delta-time wouldn’t make sense. In the end, the velocity will be time-integrated to give a position change.

If you were increasing the velocity though (accelerations) then you’d want that to be time independent so you should scale it. Of course, if you never change your fixed-time setting then you can use constants for this but if you ever change the frequency of the fixed-time then your accelerations will change so personally I’d always do it. Likewise if you were changing position and added 0.1 then if you used the fixed-update default of 50hz then on average you’d get 50 * 0.1 change in position. Not only does this mean you have to use odd values dependant upon the actual fixed frequency but also if you change that frequency it’d all go wrong.

In short, don’t treat them as having some special difference in how you scale them to give time-invariant changes. Anything that you’d do the same for per-frame should be done per-fixed-update even if you don’t initially intend on changing the frequency of the fixed-update.

3 Likes

In conclusion, multiplying with fixedDeltaTime will make the value independent of the number of physics steps in a frame. So, time.fixedDeltaTime (counter of deltaTime for FixedUpdate) should be used.

Use Time.deltaTime even in FixedUpdate, because it will return fixedDeltaTime anyway… (From Unity documentation: When this is called from inside MonoBehaviour.FixedUpdate, it returns Time.fixedDeltaTime.)
So you don’t need to switch Time.deltaTime vs Time.fixedDeltaTime depending on which method you’re in.

While we’re already piling onto a long-dead thread, barely adding new tidbits of information, you do NOT want to scale your forces by Time.deltaTime or Time.fixedDeltaTime or any other frame timing information. AddForce*(), AddTorque*() etc., already incorporate the correct ∂_t_ term into their internal math.

3 Likes

except in Impulse mode, although i can’t think of a reason to impulse continuously i’m sure there could be a use or a misuse

Thread locked due to necro posting