Hi to all,
first of all sorry for my silly question, I tried to find the answer at my question from any week in scripting reference and forum but i didn’t found it (I’m sure that there is in any place here lol!!!).
I’m begging to make the first steps in Unity scripting animation with Lerpz tutorial too, but i Have a question in particular about the Time.
I have read about delta.Time, Time.time, and Fixed Update but I really don’t understand WHY the animation that i make by a very very simple script (like in rotation for example) run differently in Editor from the builded version of the game. And the velocity of animation change for every quality of game (fastest,good,fantastic etc etc) and change again with a windowed version.
For example i used the same script of Lerpz tutorial for looping rotation of objects, in the Lerpz project if i build i,t the rotation run correctly in all cases, if I create a new project using the same script on a simple cube too, don’t run correctly if I go to build the game. What I miss? What I need to know? Is it right the animation on the game editor? On which I should trust ?game view on editor or in the builded game?
Thank you for your patience and sorry again for this so NOOOOOOB question
!!!
The script I mean :
// objectRotater: Rotates the object to which it is attached.
// Useful for collectable items, etc.
function Update ()
{
transform.Rotate (0, 45 * Time.deltaTime, 0);
}
function OnBecameVisible()
{
enabled = true;
}
function OnBecameInvisible()
{
enabled = false;
}
The issue is that the framerate is not the same for all computers and can even vary during a game played on one computer. The amount of time taken to display a frame depends on the speed of the CPU and the graphics hardware and also on the complexity of what is being done during the frame update. If you move an object by a constant amount each frame update, then it will move faster when the framerate is high (ie, you get more frame updates and the object moves the same amount each update). The way to get constant speed of motion is to multiply the distance moved per frame by the frame update time (given by Time.time). If you do this consistently throughout your code, you should find that the game behaves roughly the same in the editor and the built game. However, it is easy to miss the time scaling out by mistake and sometimes you need to do a bit of debugging to find out where the problem is.
Hi andeeee,
thank you very much for your answer, the trouble is that this rule for the animations by scripting, already I know it,about fps, delta.time and TIme.time, but I tried to use a simpleMathf.Sin of Time.time on a rotation y for example, applied it to a simply cube , so I have a very simple scene with a plane, the main camera, and the rotating cube in y by script. If i go to build it (with debug option active), when I go to test it to all quality, windowed or not, the velocity of rotation in Y change a lot respect than gameviewport simulation at editor (using Time.time too).
Time scale it’s at 1 and all options of the project are by default like when you create a new project…so I really don’t understand where I’m mistaken.
(i used the script for the pulse light of the scripting manual of unity too…and happens the same problem).
Thank you again for any helps and clarifications that you can give me :)!!!