- Home /
 
 
               Question by 
               Elliot1234 · Feb 03, 2013 at 05:09 PM · 
                androidiosaccelerometergyrojet  
              
 
              Jet Accelerometer Script
I have been trying to make a script that would allow me to tilt my device and rotate my jet up or down, left or right. so far i have had no luck and can't find anything on the internet so help would be much appreciated. Thanks.
               Comment
              
 
               
              Answer by Abhinash kumar · Mar 31, 2013 at 07:01 AM
// Move object using accelerometer variables
 var speed = 1;
 var movey=1;
 
               function Update () {
     var dir : Vector3 = Vector3.zero;
     // we assume that device is held parallel to the ground
     // and Home button is in the right hand
     
     // remap device acceleration axis to game coordinates:
     //  1) XY plane of the device is mapped onto XZ plane
     //  2) rotated 90 degrees around Y axis
     dir.x =  Input.acceleration.x;
     dir.z = movey;
     
     // clamp acceleration vector to unit sphere
     if (dir.sqrMagnitude > 1)
         dir.Normalize();
     
     // Make it move 10 meters per second instead of 10 meters per frame...
   //  dir *= Time.deltaTime;
         
     // Move object
     transform.Translate (dir * speed);
 
               }
Your answer