Help: Moving the Camera let it also rotate

Hi

I have a problem. My moving camera script lets the camera rotate around in angles. I don t know why. It should only turn the x and y axis and not rotate

Here my code

var camspeed = 5.0;
var turnSpeed = 5.0;
var mouseTurnMultiplier = 0.5;


var minPositionx : float = -5.6; // left border
var maxPositionx : float = 3.4; //  right border
var minPositionz : float = -6.5; // left border
var maxPositionz : float = 2.5; //  right border
var minPositiony : float = 0; // down
var maxPositiony : float = 4.0; //  up

function Update () {
	var x = Input.GetAxis("Horizontal") * Time.deltaTime * camspeed;
	var z = Input.GetAxis("Vertical") * Time.deltaTime * camspeed;
	transform.Translate(x, 0, z);
	transform.position.x = Mathf.Clamp(transform.position.x, minPositionx, maxPositionx);
	transform.position.z = Mathf.Clamp(transform.position.z, minPositionz, maxPositionz);
	transform.position.y = Mathf.Clamp(transform.position.y, minPositiony, maxPositiony);
	
	if (Input.GetMouseButton(1))
	{
			x = Input.GetAxis("Mouse X") * turnSpeed * mouseTurnMultiplier;
		y = Input.GetAxis("Mouse Y") * turnSpeed * mouseTurnMultiplier;
	}
	transform.Rotate(-y, x, 0);
	//Debug.Log("y: "+y+" test: ");
	
}

I’m not sure what you’re asking exactly, but this:

transform.Rotate(-y, x, 0);

Will have the effect of rotating your object incrementally about its own local axes. Among other things, this may result in accumulated perceived roll.

If you want the camera to be able to yaw and pitch while always remaining upright, you can instead store cumulative ‘yaw’ and ‘pitch’ values, and update your orientation like this (not sure about the syntax, but it should be something like the following):

transform.eulerAngles = Vector3(pitch, yaw, 0);
// Or:
transform.rotation = Quaternion.Euler(pitch, yaw, 0);