Slowing Down Time

Hi there, I’m a total newbie in Unity development and I need help with my current project. I’m currently working on a 2D Platformer which allows the player to slow down time for stronger attacks and puzzle solving.

A game with a similar idea would be Viewtiful Joe. I need scripting suggestions on what to use in order to create the time slow down effect. I would like to assign the slow down power to the shift button. How do I do it?

Factors involved:
1.) Weapons strength upon skill activation
2.) Reverting the physics/attributes back when the SHIFT(slow down) button is released

I highly welcome critics, recommendations, suggestions and things to consider while creating the project. Thanks

To start with, try playing with Time.timeScale, it’s a very easy way to control the rate of time in Unity, and the example even includes a button toggle slowdown effect.

Sorry as I’m relatively new to scripting. Do you have any suggestions on how I can test the timeScale codes out?

2 Likes

Welcome to the forum, Aeralynn!

The value of Time.timeScale is the number of seconds that effectively pass in the game for each second of real time. By default, it is set to 1, so game time is the same as real time. However, if you set it to 0.5, then the game will slow to half speed. Conversely, if you set Time.timeScale above 1, the game will run fast. You can set the value anywhere you like in any script. As the doc page says, you should generally also change the value of Time.fixedDeltaTime whenever you change Time.timeScale (ie, set them to the same value). This will ensure that physics and other updates occur at the same rate in real time rather than at the slowed game time rate.

2 Likes

Hmm don’t really fathom but will try it out…
Another thing. I want to make the players be able to hold down SHIFT to activate and release to deactivate the power. How do I get Unity to read the SHIFT key?

You can use Input.GetKey for this. The list of key identifiers is given on the Input Manager page in the manual.

I’ve assigned SHIFT for the Slow power.
How do I make my character still move at his normal speed while the world is slowed down?

if (Input.GetKey(“z”))
{
// slow down time from 1 too 0.5
Time.timeScale = .05;
}
else
{
Time.timeScale = 1;
}

1 Like

Thanks but I already got the Slow power working on SHIFT.
Only thing is I want my character to not slow down along with the scene.
Any idea on how to work on that?

I suppose an easy fix would be to increase player movement values etc when in slowmo and revert when not?

1 Like

my logic is that you slow down all the other object’s force or velocity instead of slowing down the whole time :slight_smile:

no. that’s extremely inefficient.