- Home /
Why if I Rotate only 1 axis, it rotates the other 2 axis also?
Hello!
I try to rotate with a certain value on a certain axis like X for example and the code is like this :
mouseY = Input.GetAxisRaw("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
followXRotation.rotation = Quaternion.Euler(xRotation,0f,0f);
I want to mention that the followXRotation is a child of the Camera which is a child of an empty GO and this script is attached to the empty GO. This should work but when i Rotate on X axis, Y and Z axis will have small values like random values between (-11,11(just for example)) and then when i stop rotate, the values will be 0.
When i Rotate 2 axis there is no problem and the problem is when i rotate just one axis. Does somenone knows how to solve this problem?
Answer by stephen_gregory · Nov 26, 2020 at 05:38 PM
Ok I solved my problem with some help from @jimmiewalker653 suggestion.
followXRotation.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
So you have to rotate around local axis.
Answer by jimmiewalker653 · Nov 26, 2020 at 04:57 PM
Try using localEularAngles and use mouseX in the X axis.
So you say that my rotation happens in global while i'm in local?
Your answer
Follow this Question
Related Questions
Flip over an object (smooth transition) 3 Answers
How to set a single-axis rotation and not change the others axes 1 Answer
Trouble with Camera Rotation Math 2 Answers
Why is my object's local x rotation not going past 90 degrees? 1 Answer
Weird shake when I try to rotate player according to Virtual Cameras rotation. 0 Answers