Is it good idea to multiply Mouse movement by Time.deltaTime?
float mouseX = Input.GetAxis("Mouse X") * lookSens * Time.deltaTime;
Should we use deltaTime with inputs and when should we use deltaTime with inputs?
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Sign up to join this communityIs it good idea to multiply Mouse movement by Time.deltaTime?
float mouseX = Input.GetAxis("Mouse X") * lookSens * Time.deltaTime;
Should we use deltaTime with inputs and when should we use deltaTime with inputs?
No, you should not use deltaTime
for this input.
Input.GetAxis("MouseX")
and ..."MouseY"
give you values proportional to the number of pixels the mouse has moved since the last frame
So assuming the mouse is moving in one direction over this interval, the values will already naturally be larger on long frames that cover a lot of movement, and smaller on short frames where the mouse hasn't had a chance to move as far.
If you then scale this by Time.deltaTime
, you end up double-dipping this effect: over-diminishing the effective input at high framerates, and making your game behave inconsistently.
When you multiply by deltaTime
, what you're doing is integrating or "totalling up" an instantaneous sample over that time interval, assuming it was constant for the whole interval. The same way we integrate physics effects from...
Acceleration (meters/second²)
↓ * deltaTime
(seconds)
Velocity or Speed (meters/second)
↓ * deltaTime
(seconds)
Position or Distance (meters)
So it makes sense if you're sampling the instantaneous magnitude of an analog stick, and interpreting it as a speed of motion that should be totalled over the frame to get the total distance travelled / total change in position.
But for the mouse, you're already starting with a distance — the distance travelled on the screen, not the speed of that movement — so you don't need to integrate it over the frame time.