Camera Help

Ok so I made a camera and then I put this script onto it.

	var horizontalSpeed : float = 2.0;
	var verticalSpeed : float = 2.0;
	function Update () {
		var h : float = horizontalSpeed * Input.GetAxis ("Mouse X");
		var v : float = verticalSpeed * Input.GetAxis ("Mouse Y");
		transform.Rotate (v, h, 0);
	}

it work great but, the only thing is when the camera turn it not straight it go into a 45 angle or something like that. I just want it when you move the mouse left and right it move left and right, and when you move it up and down it go up and down. but down move it up and up move it down. I’m not sure how to fix this PLZ HELP.

(1) Fix the Up is down and down is up
(2) Make it so the camera go straight

  1. To switch y direction you need to multiply the y rotation by -1 so transform.Rotate(-v, h, 0)

  2. To keep the camera straight you need to make it so vertical rotations only affect vertical and horizontal only affect horizontal.

Here is an example of how both can be done

var horizontalSpeed = 2.0;
var verticalSpeed = 2.0;
var horizontalRotation = 0.0;
var verticalRotation = 0.0;

function Update() {
    verticalRotation += -verticalSpeed * Input.GetAxis("Mouse Y");
    horizontalRotation += horizontalSpeed * Input.GetAxis("Mouse X");
    transform.rotation = Quaternion.Euler(verticalRotation, horizontalRotation, 0);
}