- Home /
 
 
               Question by 
               Afavar · Jul 09, 2014 at 09:48 PM · 
                2drigidbodyaccelerometertilt  
              
 
              Rigidbody2D with Accelerometer
Hey everyone i am having a problem with the project i am working on. It is a 2D project. I have a rope made with 2D hinge joint. And i want to control the weight that is connected to rope(again with 2D hinge joint) with Accelerometer. I am using the code below. The problem is the weight moves strange i mean it is definetly not smooth. I think it is because that it has a rigidbody and the code below i forcing it to move a position. I am not sure what to do. And i am holding the device portrait position. What should i change?
     // Move object using accelerometer
 static var useTilt : boolean = true;
     
 function Start ()
     {
     Time.timeScale = 1.0;
     }
     
 function Update () {
     if(useTilt)
         {
     
         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;
         
         
         // 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);
         }
     }
 
              
               Comment
              
 
               
              Your answer