Ok so here is my third attempt but with no success. right now it just freezes the game after a few seconds and does not look any where just straight up. Is there something I missing with this? I am basing it off the mouse look at script in the standard assets.
Here is what I have so far: Thanks for any help with this
var turnSpeed : float = 15f;
var minX :float = -90;
var maxX : float = 90;
var minY : float = -90;
var maxY :float = 90;
var rotationX : float = 0f;
var rotationY : float = 0f;
var originalRotation : Quaternion;
var xQuaternion : Quaternion;
var yQuaternion : Quaternion;
function Start () {
}
function Update () {
//rotate the comera
//this works
this.transform.RotateAroundLocal(Vector3.up, Input.GetAxisRaw("Vertical") * turnSpeed);
this.transform.RotateAroundLocal(Vector3.forward, Input.GetAxisRaw("Horizontal") * turnSpeed);
if(Input.GetAxis("Vertical"))
{
rotationX += Input.GetAxis("Vertical") * turnSpeed;
rotationX = ClampAngle(rotationX, minX, maxX);
}
if(Input.GetAxis("Horizontal"))
{
rotationY += Input.GetAxis("Horizontal") * turnSpeed;
rotationY = ClampAngle(rotationY, minY, maxY);
}
xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
yQuaternion = Quaternion.AngleAxis (rotationY, -Vector3.right);
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
}
static function ClampAngle(angle :float, min : float , max :float )
{
if (angle < -360F)
angle += 360F;
if (angle > 360F)
angle -= 360F;
return Mathf.Clamp (angle, min, max);
}