-3
\$\begingroup\$

I found a simple script in C# in Unity5 to make the camera follow the mouse:

xRotation -= Input.GetAxis ("Mouse Y") * lookSensitivity;
yRotation += Input.GetAxis ("Mouse X") * lookSensitivity;
transform.rotation = Quaternion.Euler (xRotation, yRotation, 0);

I understand why the y-axis is used for xRotation and visa versa. I just don't understand why if I change xRotation -= ... to xRotation += ... it inverts it and the same with yRotation.

\$\endgroup\$
1
  • \$\begingroup\$ Might I ask why my question is being down voted? \$\endgroup\$ Apr 27, 2016 at 0:46

1 Answer 1

2
\$\begingroup\$

It has to do with the way the coordinates systems are set. In particular, what it means to increment the Y coordinate for the mouse? an on the screen?. I'm not sure which convention Unity follows, but to put an example. The mouse coordinates might be (0,0) at the top-left corner and Y would increase when moving the mouse downward. On the other hand, the screen coordinates might have a Y component that increases when going up. That's why you need to flip the sign of Y but not for X, as increasing X, both for the mouse and on screen means moving to the right.

\$\endgroup\$
1
  • \$\begingroup\$ mouse Y has a possitive value when going up and a negative when going down in unity. \$\endgroup\$
    – Uri Popov
    Apr 26, 2016 at 10:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .