- Home /
Check accelerometer's rotation Android
Hi Unity users
I am making a game which allows player to move left and right using tilt controls I want to check whether android device is rotated in the specific direction. For instance, if device is rotated to the left, then player moves to the left. I hope you get my idea :P
Documentation didn't help me. Other's answers and forums didn't help me either!
Thanks in advance!
Answer by AirBiscuit · Jul 21, 2014 at 03:01 PM
Translate the object by the amount of acceleration on the axis
void Update()
{
Acceleration = Input.acceleration.x;
transform.Translate(Acceleration, 0, 0);
}
//Or if that doesn't work/moves things the wrong way
void Update()
{
Acceleration = Input.acceleration.y;
transform.Translate(0, Acceleration, 0);
}
Try making that into a script and attaching it to the object you want to move
Answer by MakeCodeNow · Feb 18, 2014 at 06:11 PM
The accelerometer doesn't really have an orientation. It measures acceleration along three axis that are aligned with the device itself. Gravity is a constant acceleration, and will show up on one or more of those axes.
Here's another answer that goes into some practical details.
Your answer
![](https://koobas.hobune.stream/wayback/20220613133931im_/https://answers.unity.com/themes/thub/images/avi.jpg)