- Home /
Question by
KerryURKRAFT · Nov 15, 2013 at 12:20 PM ·
camerarotationstop
Stop Camera Rotation
Hi, I can't figure out how to stop the camera rotation arrived at a certain angle. Imagine a man stretched out which must look right and left and his view can't go over a certain angle. I tried many solutions and this is one of them, but it's not exactly the effect I wanted to give.
void Update () {
if (State2 == true)
{
// Camera poiting at the ceiling
Mytransform.localRotation = Quaternion.Euler(-65,0,0);
// reverse axis
y += Input.GetAxis("Mouse X");
x -= Input.GetAxis("Mouse Y");
Quaternion rotation = Quaternion.Euler(x, y, 0);
Mytransform.localRotation *= rotation;
if (Mytransform.localEulerAngles.y > 35f)
{
Mytransform.localEulerAngles = new Vector3( x, 35f, 0);
}
}
}
Comment
Answer by tanoshimi · Nov 15, 2013 at 12:32 PM
Use Clamp to limit the rotation values before setting localRotation. e.g.
y += Input.GetAxis("Mouse X");
y = Mathf.Clamp (y, minimumY, maximumY);
Then get rid of this bit:
if (Mytransform.localEulerAngles.y > 35f)
{
Mytransform.localEulerAngles = new Vector3( x, 35f, 0);
}