- Home /
Pause game that not using deltatime for movment
Hi all!
i know there is a lot of answers about pausing a game, i read most of them and in most of them the answer was: "use time.timescale = 0". it seems to me like the right way but there is one problem, it doesn't work! i tried to figure out why and i come to conclusion that it might be related to the fact that my game object is move by code like:
void update()
{
if (move = "yes")
{
x+=1 ;
object.transform.position.x+x;
}
}
........
it's not the real code, just a sample of what i have done. but the point is that there is no use of deltatime here... so my questions are:
A. am i right? B. is there any other method to pause game? some integrated function like: "application.pause" ... or something...
thanks!
Answer by gregzo · Jul 31, 2013 at 06:56 AM
Update is still called when timeScale is set to 0. Else, how would you unpause the game? It is good practice to multiply by Time.deltaTime when moving/rotating/applying force, as it makes movement frame rate independent and allows pausing.
Consider this: a cube moves by 1 unit per frame. At 60 fps, it will move 60 units per second. At 30 fps, 30 units per second. If frame rate is unstable, your cube's movement will be erratic as well.
Now, if the cube moves by 60 units per second multiplied by Time.deltaTime, whatever the frame rate the speed will stay constant.
And, because of that deltaTime multiplication, if timeScale is set to 0, the cube will stop.
so according to this the answer to A is that i'm right. but i will have to check this with my code... i guess it should be:
(object.transform.position.x+x) * time.deltatime
and about B, does time.timescale=0 is the formal way to pause game?
Transform.position.x + speed*deltaTime ( it is the the mouvement which should be multiplied by deltaTime, not the position).
Aout B, yes, most people use timeScale to pause afaik.
right! ok... and since my gameobject should move along X OR Z axis (with turns of 90 degrees ) it wan't effect this kind of movement but make it more smooth and allow me to pause it. i will test it later today and mark this question as resolved if it work well. thank you so far.
O$$anonymous$$, i added the Time.deltatime and now the game pause. problem is now the movement far from being smooth. i'm testing on tablet device and the movement seems jerky then smooth. i have a camera that follow my object. tried the lerp like other topics suggest but it doesn't help... any idea?
O$$anonymous$$! i resoled also the jerky movement by put the camera follow in: Void LateUpdate() ins$$anonymous$$d of Update().
thanks for the help!
Your answer
Follow this Question
Related Questions
Couldn't resume once Time.timeScale is set to 0 1 Answer
TimeScale = 0 crashes Unity 1 Answer
Pause menu... Isn't pausing everything... 1 Answer
How to Appease a pause menu in a game that changes it's time scale? 1 Answer
Pause, Unpause 1 Answer