transform.Rotate and transform.eulerAngles not working for player's camera.

From what I know, both transform.eulerAngles and transform.Rotate(with Space.World) both rotate with respect to the scene’s axis(and not the object’s axis).
I sort of verified this with a rotating cube, and both gave the same results(Up until eulerAngles decided to give up on me at Y=360 for some reason, cube won’t rotate I think cause it’ll go negative or something, read up and someone said it should only be used for human input since it’s unreliable, giving different output each time. Reason why i’m trying to use transform.Rotate instead). But when I try to use the mouse input, they suddenly act very differently.
transform.eulerAngles += new Vector3(-Input.GetAxis("Mouse Y")*mouse_Sensitivity, Input.GetAxis("Mouse X")*mouse_Sensitivity, 0);
//This works fine in the editor, just that sometimes it also rotates in z for some reason, when I push my mouse up vertically as high as it would go, and slide it horizontally.
transform.Rotate(0f, Input.GetAxis("Mouse X") * mouse_Sensitivity, -Input.GetAxis("Mouse Y") * mouse_Sensitivity,

Not sure how this failed. It’s only supposed to rotate in two axes, but I checked and the camera rotates in x, y, z, which makes the camera all wonky. I can finagle the thing, but if i’m not careful(like moving my mouse diagonally) i’ll rotate in all 3 axes.
How would I make it so that my camera will only rotate in horizontal and vertical axes(and not in the z axis, which will tilt your camera)? And why is it that transform.Rotate does not work the way i want it to?(and transform.eulerAngles to a smaller extent)

Thanks!

you are Rotate Z, because you pass
-Input.GetAxis(“Mouse Y”) * mouse_Sensitivity as Z, you don’t want to rotate Z then , let it be 0 and aren’t you suppose to pass
-Input.GetAxis(“Mouse Y”) * mouse_Sensitivity as X

transform.Rotate(-Input.GetAxis("Mouse Y") * mouse_Sensitivity, Input.GetAxis("Mouse X") * mouse_Sensitivity, 0);

transform.eulerAngles will work fine if only 1 axis rotate beyond 360 degree and yes you have to dealing with negative
I use transform.eulerAngles for my cam cuz i know i only rotate beyond 360 degree only X axis , my Y axis I Clamp it between 70 degree and -30 degree. and my Z always 0

1 Like

Camera work is tricky. You might want to consider just using Cinemachine since it takes care of a lot of stuff for you.

1 Like

Ah thanks i’l see if I can try haha

1 Like

oh didn’t know about this, thanks!

1 Like