- Home /
The question is answered, right answer was accepted
On time slow down only player enable to move
hi, i am using to Time.timeScale for slowing down time by pressing "t". I am getting everything slowed down including the player. Is there anyway to slow down everything except the player. here is my script, i have still some works to do, like adding a coroutine for making the time slow down temporary.
var slowammount: float = 0.2;
var visible;
var skin:GUISkin;
var slowtex : Texture;
function Start()
{
Time.timeScale = 1;
visible = false;
}
function OnGUI()
{
if (skin != null)
{
GUI.skin = skin;
}
if(visible == true){
if(Time.timeScale == slowammount) {
GUI.DrawTexture(new Rect(0,0,Screen.width, Screen.height), slowtex);
}
}
}
function Update ()
{
if (Time.timeScale == 1)
{
if (visible == false){
if (Input.GetKeyDown("t"))
{
visible = true;
Time.timeScale = slowammount;
}
}
}
}
Answer by fafase · Aug 06, 2013 at 09:07 AM
Not everything slows down when you set timeScale, only the actions happening in the FixedUpdate or anything using deltaTime or other Time members.
You could get your player going normal speed while everything is slowed down around making its move time independant:
player.Move(direction*speed);
Then, timeScale won't matter. On the other had, you are not machine independent anymore as you are moving per frame and some computers go faster than others.
You can then use a little trick using Time classes again (I know I said no more time thing but hold on).. You can use store the previous Time.time and subtract the new one.
float previous;
float delta = Time.time - previous;
previous = Time.time;
player.Move(direction*speed*delta);
can you please tell me how to add this and where? and if there is a tutorial or a documentation!!
pretty much the way I did. The previous variable is a global one so right on top of the class, the rest happens in the Update.
should i create a new script!! i mean in which script i should put this!
@Jamora, you are totally right. But the question is about getting timeScale to 0 meaning deltaTime becomes also 0.
You may need to open up the character controller script and find all occurences of deltaTime and replace it with your own delta.
You only need this in the script you want to keep on running full speed when other are low speed.
Answer by Joyrider · Aug 06, 2013 at 09:02 AM
well, you'd have to manually modify all that is related to the player by multiplying with the inverse of the timeScale, to get everything to normal speed again.
So if timeScale was 0.5f: You'd have to change the player's animation speed to
animation["Walk"].speed = 1 / Time.timeScale; // The animation will thus play at speed 2, but since the timescale reduces time by half, you get your normal speed again.
and change it back if your timeScale changes
thnx, i am using the default fps character comes with unity not the third person controller. There is no walk or running animation in the fps!!
Well, just replace the "Walk" with whatever animation name you have. This was just an example.
Follow this Question
Related Questions
collider then change rotation converse? 0 Answers
my player doesn't move at the proper speed for a random time after the level has loaded 1 Answer
space shooter tutorial, cannot move player 1 Answer
Player moving opposite direction when there is a new touch. 2 Answers
How can I convert LOCAL transform.forward to WORLD Vector3? 2 Answers