- Home /
The question is answered, right answer was accepted
Time.deltatime is returning 0?
So in scene 1 I'm moving my camera using Slerp as shown below:
theCamera.transform.rotation = Quaternion.Slerp(theCamera.transform.rotation, NextCameraPosition.rotation, Time.deltaTime * 2.25f);
theCamera.transform.position = Vector3.Slerp(theCamera.transform.position, NextCameraPosition.position, Time.deltaTime * 1.75f);
So the logic is I press button 1 in scene 1 and it slerps. This works. If I go to a new scene then go back to scene 1 and press button 1 the slerp doesn't work. After about 2 hours of debugging I realized it is because Time.deltaTime is returning 0.
Has anyone experienced this? I didn't even know that could happen.
I added a debug button that just prints out Time.deltaTime. When I run my game and hit the debug button I get around 0.002. Once I go to a new scene then go back to my first scene the debug button prints out 0. So somehow some way time.deltaTime is returning 0.
Any information on the subject would be greatly appreciated. Thanks.
please post your solution as answer and don't include it in your question. Post an answer and accept it to close the question.
you could try:
var myScale = 1;
function Start()
{
Time.timeScale = myScale;
}
Answer by trs9556 · Apr 27, 2013 at 12:51 AM
So I figured it out for anyone else interested. The way I was returning to scene 1 was causing it. To go back to the "main menu, aka scene 1" I had to open up the pause menu.
The way I pause my game is by setting Time.timeScale to 0. So when I went back scene 1 timeScale was still set to 0 therefore deltaTime was returning 0.
I changed timeScale back to 1 and it works perfectly. Thanks for attempting to help for anyone who is reading this. (sorry it took so long bunny, and I didn't post it the first time because I figured it out before the post got approved, so I wasn't able to)
Nice one!! I just spent two hours investigating this Now I know exactly what is happening.
You my friend, are awesome!!
Cheers
@greenlotus: Now you should have enough karma to upvote the answer ;)
Follow this Question
Related Questions
2nd independent deltaTime and timeScale variables, or a way to mimic this? 1 Answer
CountDown Timer Help (Seconds problem) 2 Answers
Multiply deltaTime to arrive at point2 in 1.5 sec ? 1 Answer
Pause game that not using deltatime for movment 1 Answer
Time Manager Class Implementation Like Coroutine in Unity 1 Answer