Why do you use multiplication in scripting, and how does it work? For instance, if you want to change frame-rate to seconds or something, why would you use the * symbol? Like this:
From what I understand, that changes
This is because the value of Time.time increases linearly throughout the course of your playback - counting the seconds elapsed since the playback started, whereas Time.deltaTime gives you a value which is equal to the amount of time elapsed since the last frame.
If your game is running at a steady framerate, the value of Time.deltaTime will maintain a steady value, and it will only increase or decrease in value proportionally to the variations in the framerate that your game is achieving.
So, taking your example (but using deltaTime), and assuming the game is running at, say, around 60 frames per second, the value for deltaTime would be around 0.01666.
This means the object is moved a distance of ( 5 x 0.01666 ) units each frame, and if this happens 60 times a second, it will end up moving 5 units each second.
If the framerate dropped to 20 frames per second, the value of deltaTime would rise to 0.05 (because more time elapses between frames), and you'd end up with the object moving a distance of ( 5 x 0.05 ) units each frame, but because this is now happening only 20 times a second, it still ends up moving 5 units per second.
This is why multiplying your speed by the deltaTime value gives you framerate independent code.
answered Apr 07 '10 at 03:07 PM