Interpolated Fixed Timestep

Hi, I need to know one thing to give unity a shot. I cannot implement an interpolated Fixed Timestep in unity to maintain silky smooth movement. So I would like to know how the same results can be achieved in unity. Can I just attach a physics-component to everything that moves and interacts with the environment and then turn on interpolation? (I want all of these physics things in fixedUpdate, of course, to maintain consistent game-mechanics)

If it is a valid way of doing it then I am likely sold;) However some examples use a variable step for something like jump-physics of the character. I am not a friend of it. It should be in FixedUpdate, that way you will have always exactly the same jump, on every system.

Of course that’s why we have FixedUpdate.

Some might think that FixedUpdate is running at a fix frame-rate but it’s just a fixed Update that ensures the function is called a certain amount of times per sec. This can be configured in Edit → Project Settings → Time → Fixed Timestep.

Because the Unity scripting engine uses a single thread all callbacks from Unity (Update, FixedUpdate, OnCollisionEnter, …) are done from the same thread and therefore are bound to the framerate. However FixedUpdate uses a clever trick:

FixedUpdate can be called several times a frame. Some examples:

Fixed framerate : 60 fps
Fixed timestep  : 0.01666
--------------------------
-case 1:
    Framerate    : 120fps
>Update();
               // omitted
>Update();
>FixedUpdate();
>Update();
               // omitted
>Update();
...

--------------------------
-case 2:
    Framerate    : 20fps
>Update();
>FixedUpdate();
>FixedUpdate();
>FixedUpdate();
>Update();
>FixedUpdate();
>FixedUpdate();
>FixedUpdate();
>Update();
...

That ensures that FixedUpdate is called a fix amount of time but not really at a fix rate. However it doesn’t matter since your game only provides feedback if framerate-intervals.

Time.deltaTime usually returns the time-delta between the last and the current frame. If called in FixedUpdate it returns the fixed-timestep instead. Like mentioned here you should always use Time.deltaTime since it automatically returns the correct timestep.

However sometimes it’s almost impossible to include the deltaTime in accelerated physics-calculations. You don’t have to use deltaTime but in this case you shouldn’t change the fixedtimestep, otherwise you will get a different result :wink:

Thank you for the answer. However I fear my concern is not answered. I know all these technicalities behind various game-loops and thank you for confirming that. I want to put everything in fixed update because I want to keep a consistent rule-set for everyone(my games have no performance issues), but the problem is interpolation. I know how to implement all that myself in a flexible framework that gives me access to its game-loop. But what is common practise to achieve that in unity? What I need is not deltaTime but the time “remaining time”. You can look the part below “free the physics” to see what I mean.

Thanks for your time. I hope we will find a practicable way out.