Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can someone explain what is going on with unity input?

Discussion in 'Editor & General Support' started by Crystalline, May 12, 2016.

  1. Crystalline

    Crystalline

    Joined:
    Sep 11, 2013
    Posts:
    168
    Hi.

    Look at this video I recorded. Its 8x times slower and I made it to show how unity deals with input .

    As you can see, it takes quite a bit of time for Unity to notice I started moving my cursor.. Why is it so slow? I have Vsync off,mouse script is second or first in script execution order, 60 stable fps(simple scene too).
    It is really bad, bad aim accuracy for a shooter game.Any other games I play have crisp mouse response.
    Why is this? Is there anything to do?
    I ve seen this question actually been asked before by others, but nobody wants to deal with it .Seems like devs want to dodge the question/issue.




    Also, check this out.
     
  2. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    I dont know if there really is something on unity side causing the mouse to be slow, but can we see some code just in case it might be something on your side?
    For example, I used to do Input.GetAxis("Mouse X") * Time.deltaTime, but later learned you are not suppose to multiply it by deltaTime since the value Mouse X returns is the distance the mouse moved since last frame, which is already framerate independent.
    Multiplying it by deltaTime will now make it framerate dependent, which is bad.
     
  3. Crystalline

    Crystalline

    Joined:
    Sep 11, 2013
    Posts:
    168
    Code (CSharp):
    1.  
    2.         if (axes == RotationAxes.MouseXAndY)
    3.         {
    4.             float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
    5.            
    6.             rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
    7.             rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
    8.            
    9.             transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
    10.         }
    11.         else if (axes == RotationAxes.MouseX)
    12.         {
    13.             transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
    14.         }
    15.         else
    16.         {
    17.             rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
    18.             rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
    19.            
    20.             transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
    21.         }
    22.     }
    As you can see, this code does not use any timeDelta.
     
  4. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987
    Edit - My tests were flawed so all the results are wrong. See this thread for an update
    https://forum.unity3d.com/threads/input-seems-delayed-in-old-and-new-at-least-mouse-does.404512/

    --------

    I was curious, so I did a test and it seems that unity does have some delay with inputs, though I dont think this is your issue.
    Its hard to tell with your video, but is your issue that your mouse feels like its being smoothed? Maybe thats just the slow motion you did that is making it look weird to me. Also, those mouse trails makes it hard to tell what is a single frame and what not.

    There was a bug about VR causing input lag. Do you have that enabled?
    Edit -> Project settings -> Player -> Other Settings and under "Rendering" make sure "Virtual Reality Supported" is unchecked.
    Source - http://forum.unity3d.com/threads/input-lag-in-build-when-vr-enabled.341525/

    Here was my input test...
    (The video says my framerate was 170, but I think it was actually around 100 due to the recording making things slower, but that shouldnt matter anyways)
    Edit - Removed video due to inaccurate test

    The mouse code was just this
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class Mouse : MonoBehaviour
    5. {
    6.     public float speed = 10000;
    7.  
    8.     void Update()
    9.     {
    10.         transform.Rotate(0, Input.GetAxis("Mouse X") * speed, 0);
    11.     }
    12. }

    It seems to be on average a 2 - 3 frames delay (never lower than 2, and actually, I might have never gotten 2, only 3). I was expecting 0 - 1 frame delay. When I tested in a non unity game, I seemed to be getting 0 - 2 frames delay, which makes me wonder what might be going on. I never seemed to get 3 frame delay in the non unity game though, mainly 2 frame delay, though maybe my tests are just faulty?

    Edit - I also did a test with 15 framerate lock, and it seems the input delay was still 3 frames, which means the lower your framerate, the more you will notice the input delay. Its as if for some reason unity needs 3 frames before updating the mouse values (and possibly all input values).

    I tried testing keyboard input by bringing up windows On Screen Keyboard, which will highlight the shift key when pressing it, however, it seems the On Screen Keyboard doesnt highlight in time consistently since in my recording unity would react to my input sometimes before or after the On Screen Keyboard highlighted.

    Now I too would like to get some input from the people at unity (no pun intended =D).

    Maybe this will soon be fixed with the new unity input system?
    It states -

    "Is it possible to poll input at higher frequency than the frame rate?
    Not yet but it's planned. It will be possible to get the input in event form and check the time-stamps of each event. Alternatively it will also be possible to just poll the input state in FixedUpdate rather than Update.
    "

    source - https://sites.google.com/a/unity3d.com/unity-input-advisory-board/faq

    Though, if unity is already not detecting input changes between multiple frames, would a higher frequency even matter?
    Is this bug reporting worthy?
     
    Last edited: Mar 21, 2017
  5. Crystalline

    Crystalline

    Joined:
    Sep 11, 2013
    Posts:
    168
    Very good video demonstration. It is now clear that unity input is lagging behind.
    I got no idea why the developers took no time to fix this untill now. It should ve been fairly simple, maybe?

    What I notice, is a delay when I start moving the mouse, and when I stop( obviously , its still there while continously moving it).
    The video I recorded is quite unprofessional, but you can easily see how much it takes for unity to notice and start moving the camera.The cursor is way ahead of unity camera movement.

    However,I decided to test this in Blender Game Engine, which is quite an old engine based off Blender ,and I was surprised of how much more responsive the mouse input felt.Not to mention how crisp it feels in Counter Strike or Call of Duty games.

    Hopefully this issue will be solved in the upcoming input system!
     
    Last edited: May 14, 2016
    HiddenMonk likes this.
  6. HiddenMonk

    HiddenMonk

    Joined:
    Dec 19, 2014
    Posts:
    987