- Home /
Mouse Script Reversed (y and x axis)
Hey, I've been following some tutorials, and I finished the mouse looking script. When I run the script, the x and y axis are sort of reversed. Like when I slide left and right on with my mouse it looks up and down, and when I slide up and down, it looks left and right...? Can anyone help?
pragma strict var lookSensitivity : float = 5f; var xRotation : float; var yRotation : float; var currentXRotation : float; var currentYRotation : float; var xRotationV : float; var yRotationV : float; var lookSmoothDamp : float = 0.1; function Update () { xRotation -= Input.GetAxis("Mouse X") * lookSensitivity; yRotation += Input.GetAxis("Mouse Y") * lookSensitivity; xRotation = Mathf.Clamp(xRotation, -90, 90); currentXRotation = Mathf.SmoothDamp(currentXRotation, xRotation, xRotationV, lookSmoothDamp); currentYRotation = Mathf.SmoothDamp(currentYRotation, yRotation, yRotationV, lookSmoothDamp); transform.rotation = Quaternion.Euler(currentXRotation, currentYRotation, 0); }
Answer by robertbu · Oct 15, 2013 at 01:10 AM
This will be true for almost any script that uses Input.GetAxis(). That is, a user expects horizontal mouse movements will rotate your object around it 'Y' axis, and vertical movement will rotate something around the 'X' axis. Reverse your assignment to currentXRotation and currentYRotation.
Thanks, but how exactly do I do that? Haha Sorry! I'm used to Java, not JavaScript.
Just reverse your inputs:
transform.rotation = Quaternion.Euler(currentYRotation, currentXRotation, 0);
You may have to negate one or the other.
Your answer
Follow this Question
Related Questions
How to use Configurable Joints and DragRigidBody Script with a door 0 Answers
Gun Sway Script glitching 0 Answers
Acceleration script 2 Answers
How can I make my character move only in one axis or direction at a time? 0 Answers
Footstep Script (NullReferenceException: Object reference not set to an instance of an object) 1 Answer