android - Accelerometer detects rotation instead of acceleration -


i'm trying device acceleration in unity move object

public class exampleclass : monobehaviour {     public float speed = 10.0f;     void update() {         vector3 dir = vector3.zero;          // assume device held parallel ground         // , home button in right hand          // remap device acceleration axis game coordinates:         //  1) xy plane of device mapped onto xz plane         //  2) rotated 90 degrees around y axis          dir.x = -input.acceleration.y;         dir.z = input.acceleration.x;          // clamp acceleration vector unit sphere         if (dir.sqrmagnitude > 1)             dir.normalize();          // make move 10 meters per second instead of 10 meters per frame...         dir *= time.deltatime;          // move object         transform.translate(dir * speed);     } } 

but when run game on device, object moves , stops depending on orientation of device , not it's acceleration.

i tried print input.acceleration readings

gui.button(new rect(10, 10, 150, 80), input.acceleration.x + "\n" + input.acceleration.y + "\n" + input.acceleration.z); 

and noticed 3 numbers' values change when rotate device, , value changes -1 , 1.

i know that accelerometer used measuring acceleration ,not rotation. , sensor measures rotation gyroscope.

why happening? how can read acceleration instead of rotation.

most of devices have gyroscope these days try input.gyro.useracceleration

note on of android devices gyroscope turned off default , need set input.gyro.enabled true.


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo