- Home /
speed * Time.deltaTime = 0?
Hello, I have a strange problem, I'am trying to make something rotate in the OnGUI void. But when I try to use "speed * Time.deltaTime" the float value gets 0. Here is my code:
if(GUI.RepeatButton(new Rect(0, (Screen.height / 2) - (rightButtonAverage / 2), rightButtonAverage, rightButtonAverage), "", GUIRight)) {
transform.Rotate(0, RotationSpeed * Time.deltaTime, 0);
}
If I print the "RotationSpeed * Time.deltaTime" it says that the value is 0 and it doesn't rotate, but when I delete the Time.deltaTime part, it works, although it goes faster when the game's FPS number is bigger.
Thanks, Andreas
Here is a screenshot http://imageshack.us/a/img692/3926/errorht.png
Answer by robertbu · May 28, 2013 at 03:10 PM
Time.deltaTime is very small. On average it is 1/(frame rate). For 60 FPS, it would be about .017. So your RotationSpeed needs to be fairly large. It should be the degrees per second you want the object to rotate, so try a value like 90.
I tried to change the speed to about 90, but that didn't help eather. The Time.deltaTime is exactly 0 when it get's printed in the console, but the first 1 second of the runtime, the value is something like -1.168345, but then it changes to 0 very very fast and do not change again.
Are you changing Time.timeScale anywhere (pause functionality perhaps)? Also check Edit/Project Settings/Time to make sure Time Scale is set to 1.0 in the editor. There's nothing wrong with your rotation code above, so the problem is elsewhere.
I moved it to the update void, so I guess it just doesn't work in the OnGUI void, thanks for you help :)