I’m using a simple mouse look script. But I want to limit my X rotation around -45 and 45. How can I do that thank you! I just want my camera can’t see the sky or rotate to the back of my character. Thank you.
Vector2 mouseLook;
Vector2 smoothV;
public float sensitivity = 4.0f;
public float smoothing = 2.0f;
private GameObject character;
void Start () {
character = this.transform.parent.gameObject;
}
// Update is called once per frame
void FixedUpdate () {
var md = new Vector2 (Input.GetAxisRaw ("Mouse X"), Input.GetAxisRaw ("Mouse Y"));
md = Vector2.Scale (md, new Vector2 (sensitivity * smoothing,sensitivity * smoothing));
smoothV.x = Mathf.Lerp (smoothV.x, md.x, 1f / smoothing);
smoothV.y = Mathf.Lerp (smoothV.y, md.y, 1f / smoothing);
mouseLook += smoothV;
transform.localRotation = Quaternion.AngleAxis (-mouseLook.y, Vector3.right);
if(character !=null)
character.transform.localRotation = Quaternion.AngleAxis (mouseLook.x, character.transform.up);
}
}