title: Gyroscope input and Clock arthematic in UnityScript Unity3d
body: <p>n00b question and I don't even understand enough to be able to Google well (or understand the answers appropriately).</p>
  
  <p>I'm exploring Unity 3D and playing with Gyroscope input The issue is that each axis of the gyro returns values between -1 and +1 with 0 being the devices orientation when the gyro is enabled, where +1 &amp; -1 share a border (like 12 on a clockface).  However, the gyro's 0,0,0 point is not being reset when the gyro is enabled.  The unity forums suggest deactivating the then re-activating the gyro will help - it doesn't. </p>
  
  <p>In effect the gyro's 0 point is static in the current version of iOS &amp; Unity, which means I need to 'offset' it to take into account the phone's starting position.</p>
  
  <p>My plan was to have something like:</p>
  
  <pre><code>var GyroOffset : Quaternion; 
  var CurrentGyroAttitude : Quaternion;
  var DeadSpotXPos : float;
  var DeadSpotXPos : float;
  var ThresholdPos : float;
  var ThresholdNeg : float;
  
  function Start() {
    Input.gyro.enabled = true;
    Input.gyro.UpdateInterval = 0.001;
    GyroOffset = Input.gryo.attitude;
  }
  
  function Update() {
    CurrentGyroAttitude = input.gyro.attitude - GyroOffset;
  
    if (CurrentGyroAttitude.x &gt; ThresholdPos) DoSomething(1);
    if (CurrentGyroAttitude.x &lt; ThresholdNeg) DoSomething(-1);
    if (CurrentGyroAttitude.x &gt; DeadSpotXPos &amp;&amp; 
           CurrentGyroAttitude.X &lt; ThresholdPos) DoSomethingElse(1);
    if (CurrentGyroAttitude.x &lt; DeadSpotXNeg &amp;&amp; 
           CurrentGyroAttitude.x &lt; ThresholdNeg) DoSomethingElse(-1);
  }
  </code></pre>
  
  <p><em>*</em> Where DoSomething(arbitraryFloat) and DoSomethingElse(anotherArbitraryFloat) does things that I want done and arbitrary float is not related to Gyro output.</p>
  
  <p>As the Gyro output is between -1 and +1, we could reach a case where CurrentGyroAttitude.x could legitimately be -2 or +2.  The problem with this plan is that I have to "offset" to my thresholds &amp; deadspots as well which becomes "not neat" for tuning purposes.  I'd much rather only manipulate the CurrentGyroAttitude.</p>
  
  <p>However, I don't know how to do "clock face arthematic" in UnityScript.  I think I'm talking about modulus mathematics but I keep running into complex mathematics about crypto that's doing my head in. :)</p>
  
  <p>Can anyone walk me through "cleaning" the gyro attitude output so that my clean output stays between -1 and +1, once 'offset' has been taken into effect?  </p>
  
  <p>Incidentally if anyone can shed light on Unity's GyroUpdateInterval that would be awesome because the documentation doesn't explain what the updates are measured in, or what the effect of manipulating is.</p>