- Home /
How to create the effect of stoppage time?
I would like to know how to create an effect similar to the drying time, the style Time.timescale = 0, that everything was stopped, so I could only perform actions.
Thx in advance
Answer by Bampf · Mar 22, 2011 at 02:44 PM
Your question isn't entirely clear, but I'm assuming that you don't want to use timescale=0 because you want some things to stop and others to continue?
Here is one way to get the effect you want. Define your own floating point time variable, let's call it myCurrentTime. In Update, set myCurrentTime = myCurrentTime + Time.deltaTime, but only when the game is not paused.
Now the things that you don't want to be frozen (lerps and tweens, for example) should use Time.currentTime. The things that freeze would use myCurrentTime. You have absolute control whether myCurrentTime updates or not. You can also slow down time with it.
With this scheme is that you can freeze all physics and particle systems with timeScale=0, and keep most other things running on your time scale. Or you can do the opposite: keep physics running while myCurrentTime is frozen.
What you can't do with this idea is freeze some physics while the rest continue to run. If you need that, then you'll have to write code that freezes only the objects that needs freezing. This might involve marking them isKinematic to turn gravity off, and having code which moves them leave them alone when the game is paused. For a particle emitter you might need to deactivate it, then walk the list of particles, zeroing their velocities. You'd have to save those velocities and restore them later to unfreeze them. Etc.
Or, for some games it might be easier to not use built-in physics at all, and do all the movement with your own code. Then you could freeze and unfreeze individual objects at will.
So it can get quite complicated, depending on the game.
Thanks for your GREAT answer, opened my $$anonymous$$d a bit how to do this feat, I am very grateful and I'll try later, anything post here