So I have edited a few small things in the original mouselook script to have it rely on a rightclick system and be restrained to a certain degree of rotation. Everything works great except that even tho I managed to get it to stay within 180 degrees left to right the center of this limit seems to be looking to the characters direct right which means i am stuck looking from the front of the character to behind it on the right side… Ive tried everything but cant seem to get the limits to make it so you can only look ahead and left and right. Here is the whole script,
using UnityEngine;
using System.Collections;
[AddComponentMenu("Camera-Control/Mouse Look")]
public class MouseLook : MonoBehaviour {
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float minimumX = 0F;
public float maximumX = 180F;
public float minimumY = -60F;
public float maximumY = 60F;
float rotationX = 0F;
float rotationY = 0F;
void Update ()
{
if (Input.GetButton ("Fire2"))
{
if (axes == RotationAxes.MouseXAndY)
{
rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
Adjust360andClamp();
transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);
}
else if (axes == RotationAxes.MouseX)
{
transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
}
else
{
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
Adjust360andClamp();
transform.localEulerAngles = new Vector3(-rotationY, transform.localEulerAngles.y, 0);
}
}
}
void Start ()
{
if (rigidbody)
rigidbody.freezeRotation = true;
}
void Adjust360andClamp()
{
if (rotationX < -360)
{
rotationX += 360;
}
else if (rotationX > 360)
{
rotationX -= 360;
}
if (rotationY < -360)
{
rotationY += 360;
}
else if (rotationY > 360)
{
rotationY -= 360;
}
rotationX = Mathf.Clamp (rotationX, minimumX, maximumX);
rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
}
}
I can take a video of what I mean if you guys want? Just let me know.