How to only rotate object on x and z axes, keep the y axis as it is?

I making a shooter game. I have third person and first person cameras and mouse look is enabled only when first person camera is active. When i switch to third person i want to reset the rotation of x and z axis but the character should be looking in the same direction i.e. y axis should not be changed.

Script :-

{ = false; = true;
GetComponent(“MouseLook”).enabled = !GetComponent(“MouseLook”).enabled;
GameObject.Find(“Crosshair”).GetComponent(“Crosshair”).enabled = true;
GetComponent(“FPSMovement”).enabled = !GetComponent(“FPSMovement”).enabled;
GetComponent(“TPSMovement”).enabled = !GetComponent(“TPSMovement”).enabled; = 70.0;
{ = false; = true;
GetComponent(“MouseLook”).enabled = !GetComponent(“MouseLook”).enabled;
GetComponent(“FPSMovement”).enabled = !GetComponent(“FPSMovement”).enabled;
GetComponent(“TPSMovement”).enabled = !GetComponent(“TPSMovement”).enabled;

Thank You very much :slight_smile:

you need to use a Euler to manually assign the angles

transform.rotation = Quaternion.Euler(0,transform.eulerAngles.y,0);

this should clear the x and z rotations


just an idea:

You could do it by checking the y-checkbox on freeze rotation in the Constrains
on your Rigidbody.

The Constrains are in the inspector on the rigidbody-Component below Collision Detection

I hope this is helpfull =)

Use UnityEditor namespace. There should be Gizmo customizer.

Try something like this, I wanted to keep z axis rotation freeze. This worked for me.

this.transform.Rotate(Vector3.right, xSpeed, Space.Self);
this.transform.Rotate(Vector3.up, ySpeed, Space.World);