- Home /
 
               Question by 
               martinanugrah24 · Apr 02, 2017 at 07:18 PM · 
                androidmovementvelocityaccelerometer  
              
 
              How to make the accelerometer of object move more smoothly?
I want to make my character to move smoothly when I tilt my phone. How I can make it to move smoothly and the velocity and the speed increases as the slope of the phone?
 void AccelerometerMove()
     {
 
         float x = Input.acceleration.x;
         Debug.Log("X = " + x);
 
         if (x < -0.1f)
         {
             MoveLeft();
         }
         else if (x > 0.1f)
         {
             MoveRight();
         }
         else
         {
             SetVelocityZero();
         }
     }
 
     public void SetVelocityZero()
     {
         rb.velocity = Vector2.zero;
     }
 
     public void MoveLeft()
     {
         rb.velocity = new Vector2(-speed, 0);
         //transform.Translate(Vector2.right * speed * Time.deltaTime);
         transform.eulerAngles = new Vector2(0, 180);
     }
 
     public void MoveRight()
     {
         rb.velocity = new Vector2(speed, 0);
         //transform.Translate(Vector2.right * speed * Time.deltaTime);
         transform.eulerAngles = new Vector2(0, 0);
     }
               Comment
              
 
               
              Answer by Eldar96 · Apr 02, 2017 at 09:26 PM
@martinanugrah24 Maybe using some filters? I am new in Unity, but maybe bandpass, lowpass, highpass filters can help you. I have seen script in Unity documentation that uses hamming window. Cant find it now =/
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                