- Home /
Other
Value * deltatime / deltatime ?
Is this going to make the purpose of deltatime work ? Instead of increasing the value just multiply and divide.
Answer by Bunny83 · Sep 23, 2016 at 10:52 PM
Huh? That would be pointless. IF you multiply and divide by the same number it's like you did nothing.
"deltaTime / deltaTime" == 1.0
If that was your whole question we're done here ^^. You haven't said what this all is about.
Yes but you use deltatime, so on every computer it runs on the same speed. Let's say deltatime is 0.01 and your value is 100.
if you do 100 0.01 you'll get 1 but if you do 1 0.01 / 0.01 you also get 1.
Sorry if it's not clear but I had some speed values but when I multiply by deltatime the speed becomes slower and I don't want to find the value to get up to the speed again, so I'm asking if you get the same value of speed again if you divide it by deltatime again.
No, if you divide by deltaTime again you just revert the effect of deltaTime. As i said it's like you did nothing at all.
The point of using deltaTime is that you basically change the "unit" of a value. deltaTime must only be used when you add a value every frame.
If you do this:
float val = 0f;
void Update()
{
val += 100f;
}
You will always add 100 each frame. So when running at 100 fps "val" will be 10000 after 1 second since you get 100 frames in that one second and each frame adds 100.
If it's running on just 20 fps val will only accumulate to 2000 ( 20 * 100).
Without deltaTime the value you add has the unit "amount per frame". When multiplying the value by deltaTime before you add it, the value willhas the unit "amount per second". A second is of course a longer time than a single frame.
If you want "val" to grow by 10000 each second you have to simply use 10000 multiplied by deltaTime. This will add 100 each frame if the framerate is 100 but will add 500 each frame if the frame rate is only 20 frames per second.
void Update()
{
val += 10000f * Time.deltaTime;
}
You talked about a speed value. We usually measure speed in "distance per time unit" where distance is usually meter and as time unit we usually use "second" (at least in the metric system ^^). So when you deal with speed values that are based on second you simply multiply be deltaTime and get the right result.