transform.Rotate with z clamped to 0 [duplicate]

I have a virtual joystick to rotate the player and this piece of code works nice and smooth for the rotation of the players view.

public void rotatePlayer(Vector3 newPosition){
transform.Rotate(new Vector3(-newPosition.y,newPosition.x,0)*Time.deltaTime);
}


I pass a Vector3 with the position of the joystick in relation of his parrent's(the joystick border) anchor.That gives me the rotation direction.Which means that if I set the rotation of the camera direclty it will just flip to that point and not move progresively to that point.

Even though z is set to 0 in the vector3, it changes the z axis angle of the camera. How can I clamp it to 0 without using many resources?

I tried other methods but they just switch the camera's rotation directly when the joystick is touched like I already said.Flip and stop.

I guess I could just set the z axis rotation to 0 every time but that just seems like double work.

• Does this only happen if the camera's rotation is already different from the default or does it always happen? – Bálint Aug 9 '16 at 14:45
• Always.The x and y axis rotation affects the z rotation as much as I understand and see – Georgi Dzhondzhov Aug 9 '16 at 14:47

float rotationX = transform.localEulerAngles.x + amount to rotate x;