- Home /
 
              This post has been wikified, any user with enough reputation can edit it. 
            
 
             
               Question by 
               abhishakverma · Jan 21, 2014 at 11:12 AM · 
                camerarotationjavascript  
              
 
              Move the Object to Camera respective.
I am facing one problem with Input.acceleration. if i rotated the camera in y axis in runtime then my Input.acceleration work opposite direction.how can Move the Object to Camera respective.
 var dir : Vector3 = Vector3.zero;
 dir.x = -Input.acceleration.y;
 dir.z = Input.acceleration.x;
 
              
               Comment
              
 
               
              Answer by abhishakverma · Mar 10, 2014 at 03:09 PM
 #pragma strict
 
 
 
 
 
 // Move object using accelerometer
     var speed = 10;
 
     
     
     function Start () {
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
         
    
     }
        
        
  
 
     function Update () {
     
     
     
         var dir : Vector3 = Vector3.zero;
 
     
               
         dir.x =/*Input.acceleration.x*5;*/ Input.GetAxis("Horizontal");//Input.acceleration.x*5;//Input.GetAxis("Horizontal");//-Input.acceleration.y;
         
         dir.z =/*Input.acceleration.y*2;*/Input.GetAxis("Vertical");//Input.acceleration.y*5;//Input.GetAxis("Vertical"); //Input.acceleration.x;
         
         // 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;
         
         // stop to cross movement
         
             if(Mathf.Abs(dir.x) > Mathf.Abs(dir.z)) {
              dir.z = 0;
              }
          else {                  
                 dir.x = 0;
                }
             
         // Move object
         transform.Translate (dir * speed);
     }
 
              Your answer