Intro
In Unity, since Update() is called once per frame, if motion is coded without accounting for frame time, object speed will vary with FPS
Frame-Dependent Animation
- If you intend for an object to move 10 units/sec but don’t use
Time.deltaTime
float speed = 10f; // “10 units/sec”
void Update() {
transform.position += Vector3.forward * speed; // NO deltaTime
}- Unity interprets speed as units per frame, not per second (e.g. speed = 10 units/frame NOT 10 units/sec)
- Example: 60 FPS
- Update() runs 60 times/sec and each frame moves 10 units → total per second which is way faster than intended:
distance/sec = 10 units/frame × 60 frames/sec = 600 units/sec- To force the desired 10 units/sec at 60 FPS, you would theoretically set speed to 0.166:
speed = 1 frame × (1 sec / 60 frames) × 10 units/sec ≈ 0.166 units/frame- But if Unity drops to 30 FPS, then, it only moves 4.98 units
distance/sec = 0.166 units/frame x 30 frames/sec = 4.98Frame-Independent Animation
- To make motion frame-rate independent, multiply by
Time.deltaTime:
float speed = 10f; // units/sec
void Update() {
transform.position += Vector3.forward * speed * Time.deltaTime;
}- Now Unity scales movement by the time since the last frame, so total distance per second stays correct regardless of FPS
- Example:
- 60 FPS → distance/frame ≈ 0.167 units, total/sec ≈ 10 units
- 30 FPS → distance/frame ≈ 0.333 units, total/sec ≈ 10 units
deltaTime @30 FPS = time/frame = 1 sec/30 frames = 0.0333 sec/framedeltaTimeis basically the unit conversion from unit/sec (real-world speed) to units/frame (Unity world speed)
# transform.position += Vector3.forward * speed * Time.deltaTime;
distance/frame = speed * deltaTime
= 10 units/sec * 0.0333 sec/frame = 0.333 units/frame - Verified with Dimensional Analysis:
total distance per sec = 1 sec * 30 frames/sec * 0.333 units/frame = ~10 units



