- Home /
 
 
               Question by 
               kamuzai1226 · Sep 17, 2014 at 11:02 PM · 
                gyroscopetiltinput.acceleration  
              
 
              Input.acceleration keeps tilting past device tilt
SO I have this simple tiltControl script that I have made in order to tilt a platform using the device. The problem that I am having is that say I tilt the device 3 degrees, the script will tilt the platform past 3 degrees. My understanding of Input.acceleration is that no matter which direction I tilt it in. It will always return a value > 0. So I do not know how to make it stop tilting once it reaches the same amount the device has tilted. Maybe I need to use the gyroscope?
 using UnityEngine;
 using System.Collections;
 
 public class TiltControl : MonoBehaviour
 {
 
     public float maxPitch;
     public float maxYaw;
     
     private float yaw;
     private float pitch;
     private float tilt_x;
     private float tilt_z;
     
     // Use this for initialization
     void Start ()
     {
         
     }
     
     // Update is called once per frame
     void Update ()
     {
 
         tilt_x = Input.acceleration.y;
         tilt_z = Input.acceleration.x;
 
         pitch += tilt_x;
         yaw += tilt_z;
 
         if (pitch > maxPitch)
         {
             pitch = maxPitch;
         }
         if (pitch < -maxPitch)
         {
             pitch = -maxPitch;
         }
 
         if (yaw > maxYaw)
         {
             yaw = maxYaw;
         }
         if (yaw < -maxYaw)
         {
             yaw = -maxYaw;
         }
 
         transform.localRotation = Quaternion.Euler(pitch, 0, -yaw);
        
     }
 }
 
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Using accelorometer with device parallel to table? 0 Answers
unity horizontal and vertical axis based on gyro? 2 Answers
iPad: accelerator tilt breaks collider 3 Answers
Input.acceleration reading Issue 1 Answer
Gyroscope Magnetic North. 1 Answer