timeScale manipulation

Hi guys, I have a script that slows the timeScale down, and that works fine. I was wondering if you know of a good way to keep everything in the environment affected by the timeScale slow down except for the specific things that you want to remain at normal speed. For example, if I want the movement of enemies and wind to slow down, but I want my character to move normally and use a weapon at the normal speed, how would I accomplish that? Should I make another script with player movement and reference it in the script that slows down the timeScale, or can I accomplish all of this in one script?

I hope that makes sense.

Thank you

Assuming you are using your own character movement code and it is located in the update function, you can simply replace your *Time.deltaTime with *Time.deltaTime/Time.timeScale This will evaluate the time between frames as if it were in real time and not affected by timeScale

Hope this helps, Benproductions1

PS: if you need a more in depth explanation, just ask :slight_smile:

EXPLANATION:

When Time.deltaTime is calculated from the time in between frame calculation, it is multiplied by the Time.timeScale. Meaning that when time is going at half the rate, the Time.deltaTime will have half it’s normal value, therefore the slowdown.

To negate any multiplication in maths, you multiply by it’s inverse, aka divide. So you are replacing unity’s calculation of Time.deltaTime*Time.timeScale with Time.deltaTime*Time.timeScale*(1/Time.timeScale) or Time.deltaTime*Time.timeScale/Time.timeScale This will result in Time.deltaTime being the true time between frames value.

When you change Time.timeScale it also affects the real time between FixedUpdate calls. Note that there is no way to avoid this effect, so everything should be done in Update and not FixedUpdate.

Thats as much depth as I can give, there is nothing more to explain :slight_smile:

Hope this helps, Benproductions1