Is it possible to control Gyroscope?

Hello guys, I have read some topics about limiting gyroscope angle range like these:

http://forum.unity3d.com/threads/98828-sharing-gyroscope-controlled-camera-on-iPhone-4/page2

http://forum.unity3d.com/threads/106124-Gyroscope-Limitations

http://forum.unity3d.com/threads/10211-Restrict-camera-s-rotation

but unfortunately none of them is working for me.

Here is the script I am using and it’s working fine, but I have played with all the values trying to limit the rotation angles, but nothing happens.

using UnityEngine;

using System.Collections;

 

public class GyroCam : MonoBehaviour 

{

    

    public CamManager target;

    private bool gyroBool;

    private Gyroscope gyro;

    private Quaternion rotFix;  

    

    private GameObject camParent;

    public ScreenOrientation currentOrientation;

    

    private bool initialized = false;

    private Vector3 inititialRotation = new Vector3(90,90,0);

    

 

    

    private void init()

    {

        if (!initialized)

        {

            Transform originalParent = transform.parent; // check if this transform has a parent

            camParent = new GameObject ("camParent"); // make a new parent

            camParent.transform.position = transform.position; // move the new parent to this transform position

            transform.parent = camParent.transform; // make this transform a child of the new parent

            camParent.transform.parent = originalParent; // make the new parent a child of the original parent

            

            gyroBool = SystemInfo.supportsGyroscope;

            

            if (gyroBool) {

                

                gyro = Input.gyro;

                gyro.enabled = true;

                

            } 

            else 

            {

                print("NO GYRO");

            }

            

            initialized = true;

        }

    }

    

    private void updateScreenOrientation()

    {

        if (Screen.orientation == ScreenOrientation.LandscapeLeft) 

        {

            camParent.transform.eulerAngles = inititialRotation;

            rotFix = new Quaternion(0f,0f,0.7071f,0.7071f);

        } 

        else if (Screen.orientation == ScreenOrientation.LandscapeRight) 

        {

            camParent.transform.eulerAngles = inititialRotation;

            rotFix = new Quaternion(0f,0f,-0.7071f,0.7071f);

        }

        else if (Screen.orientation == ScreenOrientation.Portrait) 

        {

            camParent.transform.eulerAngles = inititialRotation;

            rotFix = new Quaternion(0f,0f,1f,0f);

        } 

        if (Screen.orientation == ScreenOrientation.PortraitUpsideDown) 

        {

            camParent.transform.eulerAngles = inititialRotation;

            rotFix = new Quaternion(0f,0f,0f,1f);

        }

        

                

    }

    

    void Update () 

    {

        init();

        if (currentOrientation != Screen.orientation)

        {

            currentOrientation = Screen.orientation;

            updateScreenOrientation();

        }       

        

        if (gyroBool)

        {

            Quaternion camRot = gyro.attitude * rotFix;

            transform.localRotation = camRot;

            target.SetRotation(transform.rotation);

        }

        else

        {

            target.SetRotation(Quaternion.identity);

        }

 

    }

}

So, is it possible to limit the rotation, as between -30 and 30 degrees? and reduce the rotation speed of the gyroscope? Or it works as a compass, following the coordinates of the real world?

Thank you in advance!

Your code seems to have a lot of extra stuff going on it, but essentially it sounds like you just want to Clamp the Eulerangles returned by gyro.attitude?