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

FPS Microgame bug

Discussion in 'Getting Started' started by Werewolf_by_Day, Aug 27, 2020.

  1. Werewolf_by_Day

    Werewolf_by_Day

    Joined:
    Aug 27, 2020
    Posts:
    2
    Hi there,

    I am brand new to Unity and decided to start with the FPS Microgame tutorial. I didn't get far since I just can't play a FPS without the Y Axis inverted. So under the Hierarchy section on the left I selected Main Scene and then Player to bring up the Player Input Handler in the Inspector. There is a box for Invert Y Axis, which I checked. This worked, but it also inverted the X Axis. Checking the Invert X Axis box does nothing. I opened up the PlayerInputHandler.cs in a text editor to see if I could locate the problem. This snippet seems to be where it is performing the inversion, but it doesn't look right:

    Code (CSharp):
    1.     float GetMouseOrStickLookAxis(string mouseInputName, string stickInputName)
    2.     {
    3.         if (CanProcessInput())
    4.         {
    5.             // Check if this look input is coming from the mouse
    6.             bool isGamepad = Input.GetAxis(stickInputName) != 0f;
    7.             float i = isGamepad ? Input.GetAxis(stickInputName) : Input.GetAxisRaw(mouseInputName);
    8.  
    9.             // handle inverting vertical input
    10.             if (invertYAxis)
    11.                 i *= -1f;
    12.  
    13.             // apply sensitivity multiplier
    14.             i *= lookSensitivity;
    15.  
    16.             if (isGamepad)
    17.             {
    18.                 // since mouse input is already deltaTime-dependant, only scale input with frame time if it's coming from sticks
    19.                 i *= Time.deltaTime;
    20.             }
    21.             else
    22.             {
    23.                 // reduce mouse input amount to be equivalent to stick movement
    24.                 i *= 0.01f;
    25. #if UNITY_WEBGL
    26.                 // Mouse tends to be even more sensitive in WebGL due to mouse acceleration, so reduce it even more
    27.                 i *= webglLookSensitivityMultiplier;
    28. #endif
    29.             }
    30.  
    31.             return i;
    32.         }
    33.  
    34.         return 0f;
    35.     }

    It seems like this bit of code is inverting both Axis whenever I select to invert the Y Axis. Could someone help me out with this? I haven't coded in C# before and I'm not really sure what this should actually look like if it is in fact the trouble area. I am currently using version 2019.4.9f1 (64-bit) but I was having the same issue with the previous version.

    Thanks,
    Jason
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    Is this code called for both the X and Y axis separately? That's what I suspect. Add this after line 4 to output the value of stickInputName on each call

    Code (csharp):
    1. Debug.Log(stickInputName);
    Then whatever the name is which is for the Y axis, use that name to modify line 10 to also check for that same string.

    Code (csharp):
    1. if (invertYAxis && (stickInputName == "NameOfYAxis"))
    Change NameOfYAxis above to whatever the Debug.Log statement outputs for whatever the Y axis is called. After you do that the invert feature will only affect the input axis of that specific name. You're then free to remove or comment out the Debug.Log line.

    That all is assuming I'm guessing correctly how this code is used, as I've never played with any of the recent interactive tutorials.
     
    drate_otin and edstock like this.
  3. Werewolf_by_Day

    Werewolf_by_Day

    Joined:
    Aug 27, 2020
    Posts:
    2
    That did the trick! Thank you so much for your help; I appreciate it.
     
  4. edstock

    edstock

    Joined:
    Apr 3, 2021
    Posts:
    1
    Just for Ref as I had the same issue my "NameOfYAxis" was "Look Y"
    So line 10 (my line 240) became:
    Code (CSharp):
    1. if (InvertYAxis && (stickInputName == "Look Y"))
     
    drate_otin likes this.
  5. Dredbeardo

    Dredbeardo

    Joined:
    May 5, 2021
    Posts:
    1
    Also comment out the (InvertYAxis) block near line 240
     
    Last edited: May 6, 2021
  6. OddKidToons

    OddKidToons

    Joined:
    Aug 29, 2019
    Posts:
    21
    Worked for me too! Thank you! Was driving me crazy!