- Home /
Why does Unity Documentation suggest I multiply by delta time?
The value I'm getting from Time.DeltaTime
seems to be very close to 0. I would expect it to be around 1 if it was something I should multiply by, as it is it's just reducing any value to something tiny!
If it is centred around 0 I would have thought you add the value, but the unity documentation tells you to multiply.
This seems wrong!
What am I not understanding?
Also, deltaTime is not to be used in FixedUpdate since Unity already adds it internally.
Answer by Bunny83 · Jul 15, 2014 at 09:54 PM
Time.deltaTime is the time between the last frame and the current. The time is in seconds. The point of multiplying by Time.deltaTime is to make movement or any linear change of a variable time-dependent instead of frame-dependent.
if you do something like this:
//C#
void Update()
{
transform.position += new Vector3(1,0,0);
}
you would add 1 to the x-position every frame. if the framerate is 50 fps you would move 50 units per second, if the framerate is 3000 fps you would move 3000 units and if it's just about 10 fps you only move 10 units per second.
Now if you do this instead:
//C#
void Update()
{
transform.position += new Vector3(20*Time.deltaTime,0,0);
}
you always move 20 units per second. That's because Time.deltaTime is "1/fps", so at a framerate of 50 fps the value of deltaTime is 1/50 == 0.02f. If you multiply that value with 20, which is your desired speed in units-per-second you get a value of 0.4f. So each frame you add 0.4 to the x position. That will add up to 20 after 50 frames which took exactly 1 second
To summarize: If you add up Time.deltaTime each frame like this:
// C#
float val = 0.0f;
void Update()
{
val += Time.deltaTime;
}
val will be increased by 1 every second.
Thanks! I had always thought constructor of type Vector3 was only replacing the given variables. I never knew It was adding ins$$anonymous$$d. You are a saviour Bunny63.
But how do we simply relocate our object using Vector3's constructor? Does it only add if the param equals the value? Can ypu show me how its constructor looks like?
@Nick4: Uhm the constructor parameters do only set the fields of a new vector3. What "adds" to the posirion is the "+=" operator.
The += operator is just a shorthand for:
transform.position = transform.position + new Vector3(20*Time.deltaTime,0,0);
This does exactly the same:
transform.position += new Vector3(20*Time.deltaTime,0,0);
If you add two vectors together, you actually adding the fields x,y and z component wise together and create a new vector3.
So:
//C#
Vector3 V1 = new Vector3(5,0,2);
Vector3 V2 = new Vector3(7,0,0);
Vector3 V = V1 + V2; // (12,0,2)
Ahhh I feel like an idiot I totally missed that operator. Thought it was only equals character. Staying awake all night doesn't help me for sure.
Your answer

Follow this Question
Related Questions
How to fast forward time (or just skip it) properly? 2 Answers
Why will this timer not count down? 1 Answer
Transform.position can't be changed smoothly. 2 Answers
Event System button tilt moving too fast and not working with being pushed down 0 Answers
Is SimpleMove() framerate-independent under the hood? 1 Answer