[?]Clamp rotation based on view.

Hello, how can I limit camera rotation based on player forward axis?

here is camera look part:

void Update()
    {
         rotationX += Input.GetAxis("Mouse X") * sensitivityX;
         rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
         rotationX = ClampAngle (rotationX, minimumX, maximumX);
         rotationY = ClampAngle (rotationY, minimumY, maximumY);
         Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
         Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, -Vector3.right);
         transform.localRotation = originalRotation * xQuaternion * yQuaternion;
    }

public static float ClampAngle (float angle, float min, float max)
     {
         if (angle < -360F)
             angle += 360F;
         if (angle > 360F)
             angle -= 360F;
         return Mathf.Clamp (angle, min, max);
     }

Thanks.

your clamp angle function is wrong to start with…

public static float ClampAngle (float angle, float min, float max)
     {
         if (angle < 0)
             angle += 360f;

         if (angle > 360f)
             angle -= 360f;

         return Mathf.Clamp (angle, min, max);
     }

not sure if that fix alone will fix whatever your problem is.

it works fine, and it works like it should in usual fps style controller (camera child of player), but my camera is separate transform that follows head position, because I need independed X rotation for it and clamp its rotation with given degrees based on player’s forward… Like you can see on image, player directions are different but camera look angle is the same and camera look clamp needs to base on player forward.