Search Unity

Question about proper use of Input.GetAxis and delta time

Discussion in 'Editor & General Support' started by kauaiBlake, Jul 6, 2017.

  1. kauaiBlake

    kauaiBlake

    Joined:
    Feb 28, 2013
    Posts:
    36
    Hi there,

    Our team is using mouse tracking code to move our camera using Input.GetAxis, as detailed here...
    https://docs.unity3d.com/ScriptReference/Input.GetAxis.html

    Thing is the docs say "This is frame-rate independent; you do not need to be concerned about varying frame-rates when using this value." But then the sample code below is then multiplying it by Time.deltaTime. I notice most third party online code talking about using this call also uses delta time.

    Our code improved in responsiveness when we removed the deltaTime multiplication to the value we apply to our camera facing. Now the camera responsiveness is more consistent across our game world where we can have varying frame rates. Before a different frame rate would cause a different mouse to camera feel.

    It seems that the way most community members use this call is sub optimal, since its being time corrected twice, like its delta time squared.

    Should the proper use of this call be made more explicit?
     
  2. Dreamwriter

    Dreamwriter

    Joined:
    Jul 22, 2011
    Posts:
    472
    I think you are mixing up the sample code. There are two examples, the first one showing keyboard/joystick axis controls (Input.GetAxis("Vertical")), and the second one showing mouse axis controls (Input.GetAxis("Mouse X")); the mouse sample doesn't use Time.deltaTime at all. What the documentation is saying, is that when reading the mouse delta values, the delta values are already framerate independent - if the player moves the mouse 3 inches, it has moved that 3 inches regardless of the framerate the system is going at. The user's hand isn't bound to the framerate :)