- Home /
Stop Time for Specific Objects?
Hey guys. I am well aware of how to "pause" the game by freezing time using Time.timeScale, but would it be able to only apply that effect to specific objects?
I want one object to continue it's script, animations, and movement while all of the othes stop in place, if that would be possible.
Answer by jspease · Mar 01, 2012 at 06:22 AM
This isn't very convenient, but one thing you could do is set Time.timeScale to a very small value and then multiply everything (for your unfrozen object only) that depends on time by the inverse of that value.
For example, set Time.timeScale to 0.0001, then multiply by 10000 everywhere your object's scripts use Time.deltaTime, and multiply your object's animation speed by 10000, and if your object has any particle effects on it then multiply many of their properties by 10000, and if it has a Rigidbody then do some horrible things to speed up the Rigidbody component until it feels like normal speed, and change it all back when you want time to go back to normal...
It sounds like a lot of error-prone work, and it can be (depending on how complex your object is), but I have personally used it successfully in the past. And the good part is that you only need to worry about making changes to the one object that you want to be unfrozen; all other objects in the game will be automatically taken care of by the low timeScale value and will properly resume when the timeScale is changed back to normal, as long as you are using Time.deltaTime correctly in their scripts instead of doing calculations that rely on a particular framerate.
Of course, with this method, the other objects aren't quite completely frozen, but you can set timeScale low enough that the player will not be able to tell the difference, or you could set timeScale high enough that the player can see a little slow-motion and call it a feature.
Answer by Ryan Howse · Feb 06, 2014 at 03:15 AM
I know this post is two years old, but I just wanted to add that you CAN technically stop time for specific objects, because Time.timeScale only affects things operating under FixedUpdate (as a whole). So if you have an object you want to be able to move around when something is paused you can simply put anything you want to be pauseable in FixedUpdate and your non-pauseable objects in Update. Its not the most elegant solution, but it works.
Thank you Ryan for this powerful information ! I just changed all my Update() to FixedUpdate() (except for controller inputs) and now I can animate what I want in a Pause $$anonymous$$enu ;-)
Thanks for the info. Do you know if there's a way to apply this concept to animationEvents? $$anonymous$$y scenario is particularly I want a game pause menu animation to load while everything else is subject to paused or sufficiently slow time. Thanks! Searching around and will reply here if I find a good solution
Answer by louptony · Feb 12, 2015 at 03:41 PM
If you want object to keep moving, you would not use time.timeScale
. You would need to use
rigidbody.isKinematic = true
for each of your object that you need to stop and keep the one you want to move to false
value. This way, your object would keep moving.
Answer by Berenger · Mar 01, 2012 at 02:38 AM
From what I understand, that's one of the stuff people hope to get in unity 4.0
Your answer
Follow this Question
Related Questions
Restart Problem 1 Answer
Pause Script Only Partially Works? (Gui Toggles, But Time.timeScale Does Not) 1 Answer
How to disable pausing on main menu drop down? 0 Answers
Pause game while GUI instructions displayed? 1 Answer
stop game for 1 second 2 Answers