I'm attempting to make a free look camera (like you might find in Counter Strike after dieing), but I'm having a problem of when I look around while moving, my camera will sometimes just flip over. How can I make it so the camera stays relatively flat while looking around?
Here is what I'm using now:
var turnSpeed = 10.0;
var moveSpeed = 10.0;
var mouseTurnMultiplier = 1;
private var x : float;
private var z : float;
function Update ()
{
// x is used for the x axis. set it to zero so it doesn't automatically rotate
x = 0;
// check to see if the W or S key is being pressed.
z = Input.GetAxis("Vertical") * Time.deltaTime * moveSpeed * 10;
// Move the character forwards or backwards
transform.Translate(0, 0, z);
zx = Input.GetAxis("Horizontal") * Time.deltaTime * moveSpeed * 10;
// Move the character forwards or backwards
transform.Translate(zx, 0, 0);
// Get the difference in horizontal mouse movement
x = Input.GetAxis("Mouse X") * turnSpeed * mouseTurnMultiplier/10;
y = Input.GetAxis("Mouse Y") * turnSpeed * mouseTurnMultiplier/10;
// rotate the character based on the x value
transform.Rotate(-y, x, 0);
}