I’ve been using an inverted Y axis for mouse-look since the mid-90s. Playtesting is going to be nightmare if I can’t figure out how to invert the Y axis in the new Input System.
Depends on how you use it. If you just get the values, invert it in the code by returning -y instead of just y. If it’s used by Cinemachine, there’s a Invert
checkbox.
I’m still early in this particular section of the course so I’m not sure how (or if) we’ll address it. I’ll just have to grin and bear it for now. It’s giving me a headache, though, which is frustrating because I’m really getting a lot out of the course so far.
Oh, it’s for Zombie Runner. It uses the standard assets FPS controller. Fortunately, that’s an easy fix.
When you are on the prefab, you will see the Rigidbody First Person Controller
component. If you double-click on the script box you will be taken to the script.
In the script, you will find the code for this controller. Just above it in your IDE’s code hierarchy, you should see a MouseLook
script. In Visual Studio it looks like this.
Open that script.
In there, we will add an option to invert the mouse.
At the top, you will see all the exposed properties. Add a boolean just underneath it for invert
public float XSensitivity = 2f;
public float YSensitivity = 2f;
public bool clampVerticalRotation = true;
public float MinimumX = -90F;
public float MaximumX = 90F;
public bool smooth;
public float smoothTime = 5f;
public bool lockCursor = true;
public bool invert; //<- Add this
Next, find the LookRotation
method and update the first line to invert the rotation, if the boolean is set
float yRot = CrossPlatformInputManager.GetAxis("Mouse X") * XSensitivity * (invert ? -1 : 1);
Here, we just multiply the y-rotation with -1 if invert
is set.
Now, in your component you will find a new checkbox under the Mouse Look
setting.
Checking this box will invert the camera rotation
I’m not using the Standard Assets FPS Controller, since it’s depreciated. Instead, I’m using the Starter Assets - First Person Character Controller | URP.
Nevertheless, your solution was helpful. In FirstPersonController.cs, I added the following to the end of the exposed variables:
[Header(“Mouse Settings”)]
[Tooltip(“Invert Y-axis for mouse look”)]
public bool yMouseInvert = true;
Then, in CameraRotation(), I altered this line:
_cinemachineTargetPitch += _input.look.y * RotationSpeed * deltaTimeMultiplier;
to instead read:
_cinemachineTargetPitch += _input.look.y * RotationSpeed * deltaTimeMultiplier * (yMouseInvert ? -1f : 1); // Added multiplication by -1 to invert y axis
That solved the problem and I can now actually do playtesting and enjoy it!
Thank you very much for the help!
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.