Time.timescale and framerate linked? (Unity 2d part 67. Using Time.timeScale)

I’ve continued with the course and noted something weird when using the time.timescale variable as instructed in part 67. It seems like the framerate of positioning and rendering is linked to the timescale. So the movement of the object seems to look pretty abysmal when at lower timescales but very high quality at higher timescales. Even in the lecture video it seems that his object ‘jumps’ across the screen when moving in a slower timescale instead of faster.

Is there a smoother way to manage this? Is this the result of continuously setting the timescale in the Update function? (second thing seems unlikely) I can see the use of having access to a time scale but I don’t want it to look so ‘choppy’.

Hi Dylan,

I assume that Time.timeScale also affects the number of frames in the scene. That’s probably the reason why the movement looks “choppy”.

If you don’t want to use Time.timeScale, you could write your own class which sets the value of some multiplier variable. You could multiply this variable by the player speed and everything you want to slow down or speed up.

Ah. So, the answer is that Unity recommends you adjust something called the, “fixedDeltaTime,” along with the timescale. (per https://docs.unity3d.com/ScriptReference/Time-timeScale.html)

I added
private float fixedDeltaTime;
to my GameState object,
fixedDeltaTime = Time.fixedDeltaTime;
to my Awake function, and
Time.fixedDeltaTime = fixedDeltaTime * Time.timeScale;
to my ‘Update’ and it fixed the framerate issue. This might be a wise addendum to the class; my assumption is that faster timescales would cause a framerate and performance issue if it was pumped too high, as well as the issue I saw.

Note that this is in the, “breakout”, example.

(Also note: The class covers this in a little more detail later on, so if you are searching and have found this keep watching and learn a little more; fixedDeltaTime is used all over the place and modifying it has quite a few ramifications)

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

Privacy & Terms