- Home /

# localRotation rotates by 180°

Hello! Im currently making an FPS and Im currently trying to keep the moment of my jump, but i want to be able to look around freely. I have an object (FPSController) which is the object that controls the movement and a child object (CameraRotation) which has the camera as a child object, so i can rotate my camera with the CameraRotation object. I can now look around the y-axis, but somehow i cant get the rotation of the x axis going:

```
else if(!isGrounded)
{
fpsCam.transform.localEulerAngles = new Vector3(y, 0, 0);
var xRot = Input.GetAxisRaw("Mouse X") * Time.deltaTime * lookSpeed;
fpsCam.transform.localRotation = new Quaternion(0,xRot,0,0);
}
```

With this code, my camera rotates by 180° everytime i move my mouse to the left or to the right. What I did could be complete nonsense, but Im still new to Unity so please excuse my sloppy coding. I dont expect you to provide code or anything, just simple instructions on how to fix the problem are more than enough.

**Answer** by JVene
·
Oct 22, 2018 at 05:30 PM

There is a lot one could say about what is wrong here, but let's start with the last line because that leads to an understanding that fixes everything else.

It appears you're familiar with Euler angles (your first line in the code block), but when you fashion a Quaternion (in the last line), you're fashioning the Quaternion with 4 parameters, and they are not Euler angles. Nothing in the constructor of a Quaternion will make much sense if you're not really familiar with the mathematics of quaternions (the subject of math beyond that of Unity). A quaternion (and thus Unity's Quaternion class) represents a complex number, like the imaginary numbers taught in algebra whereby the square root of a negative number becomes possible. The complex numbers taught in algebra are generally related to a 2 dimensional representation (like the imaginary numbers which have two values, an imaginary part and a real part). Quaternions, however, are complex numbers in 3 dimensions. None of the 4 parameters (x,y,z,w) have any meaning relative to rotations in Euler angles. This is the problem you're having. You are providing a value you intend to interpret as an angle in degrees, but the y parameter to the Quaternion constructor has no relationship to such an angle in the y axis.

To fix that, and therefore propagate that upwards to the rest of your code, look up the static function Quaternion.Euler, which forms a correct Quaternion object given Euler angles in 3 axis, as you're expecting. You could also consider using the eulerAngles property of localRotation as an alternative approach, or at the least in your translation between any quaternion and an orientation in 3 axis.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.

### Follow this Question

### Related Questions

FPS 3D camera view problem 0 Answers

Mouselook Is rotating Z-Axis of Camera Unexpectedly 1 Answer

sensitivity slider/ drop down help 0 Answers

iPhone joypad interfering with MouseLook 0 Answers

Switching to the player camera 1 Answer