- Home /
Shouldn't deltaTime be defined as the 1 over the time interval between two frames?
I tried to consider it like this:
Suppose an object moves 3 meters between one frame and the next, and it takes 2 secs. If you multiply them directly like in the reference example, it gives us 3 meters/ frame 2 secs /frame = 6 meters sec / frame^2, whereas what actually occurs is it moves 3 meters in 2 seconds, that is 3/2 = 1.5 meters/second.
Also, why is it that in the example, 10 meters/frame retained its magnitude to 10 meters/second?
it's called "TI$$anonymous$$E". why would it be 1/time ?? 1/time is something like Hz.
There's this code snippet that goes Input.GetAxis("Horizontal")Time.deltaTime*5 And so if you multiply the Input part (which is in meters/frame) and Time.deltaTime (which is seconds/frame) you would get meters sec / frame^2 , which is not the wanted meters/second. :)
sure dude, you're right. a really senior developer from Unity and sundry top ten Unity programmers have never thought this through.
Also all the text books on eg. arithmetic are wrong and the people people at the ISO and SI institutes missed that one.
Great work
Answer by Graham-Dunnett · Mar 04, 2013 at 11:05 AM
The script example is correct. Time.deltaTime
is definitely a time, and is the time between this frame and the last frame. So, if you were rendering at 100fps, then deltaTime
would be 0.01s. In the example the object is moving at 10m/s. It's not accelerating, just has constant velocity. So, if you multiply deltaTime
(a time) by a velocity (in metres per second) you get a distance in metres, which is how far the object moved in that time.
I didn't fully understand your math, but possibly you're making things more complicated than it needs to be.
right, one over the time interval between two frames gives you the "frames per second". deltaTime allows you to work with "real" units like m/s. So everything is time-based.
Yes, although how is "meters/frame" translated to "meters/second" by multiplying deltaTime? :D
Answer by Chronos-L · Mar 04, 2013 at 11:47 AM
distance, d = 3 meters
time, t = 2 seconds
deltaTime, x ( the time need for 1 frame to show )
Your first equation is wrong to begin with. Let's do this calculation to see why(based on your first equation)
Velocity = 3 meters/ frame * 2 secs /frame
Let frame be 1
// I don't care what frame is right now, deltaTime,
// or number of frame per second, it doesn't matter
Then,
Velocity = 3 meters/ 1 * 2 secs /1
= 6 meter * 1 second
What does 6 meter * 1 second
means? It is meaningless, it is definitely not velocity
( meter per second ), nor can it mean anything else.
Further Inspection
hen you move 3 meters in 2 seconds, your velocity, V
is
V = d/t
V = 3 / 2
= 1.5 meter per seconds
When you said d/x
(3/frame), this is not related to the original question at all, you are saying that
distance travelled per delta time
So, you are now talking about the speed required to travel 3 meter per 1 frame
If we are running 25 fps, deltaTime = 1sec/25frame = 0.04 seconds
d/X = 3 meter / 0.04 seconds
= 75 meter per seconds
Your second part is 2 sec/frame, which is t/x
, which translate to
2 seconds divides by time required to finish 1 frame
which will become, total number of frame in 2 seconds
If we are running 25 fps, deltaTime = 1sec/25frame = 0.04 seconds
t/X = 2 seconds / 0.04 seconds
= 50 frames
"Your first equation is wrong to begin with." Yes, I based this on the pdf tutorial which goes
Input.GetAxis("Horizontal")*Time.deltaTime*5
It was said that the Input part was in meters/frame, and the definition of time is seconds/frame, and so I wondered how it became meters/second when you multiply the two. :)
In this scenario, hasn't the fps already been set to 1/2 (since it took 2 seconds from one frame to the next, i.e., 2s = 1 f or 1/2 s = 1 f) ?
I am not sure about *Input.GetAxis("Horizontal")*Time.deltaTime*5*
, so I am not giving any comments.
When you said In this scenario, hasn't the fps already been set to 1/2 (since it took 2 seconds from one frame to the next, i.e., 2s = 1 f or 1/2 s = 1 f) ?
. Which scenario you are referring to? It has been 3 days, so I sort of lost track of my thoughts when I answered this question.