- Home /
Question by
awplays49 · Dec 27, 2014 at 04:08 PM ·
clampmathf.clamp
Camera rotating past clamp
why is the camera free to rotate any way it wants?
using UnityEngine;
using System.Collections;
public class CameraController : MonoBehaviour {
public int Sensitivity;
private float MouseY;
private float MouseYSet;
private float CameraAngle;
public float MaxAngle;
public GameObject CameraTarget;
void Start () {
}
void Update () {
// Rotation controls
MouseY -= Input.GetAxisRaw ("Mouse Y");
MouseY = Mathf.Clamp (MouseY, -MaxAngle, MaxAngle);
if (MouseYSet != MouseY)
{
transform.Rotate ((MouseY - MouseYSet) * Sensitivity * 10, 0, 0);
MouseYSet = MouseY;
}
}
}
Comment