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
Documentation didn’t help me. Other’s answers and forums didn’t help me either!
Thanks in advance!
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.
Translate the object by the amount of acceleration on the axis
Acceleration = Input.acceleration.x;
transform.Translate(Acceleration, 0, 0);
//Or if that doesn't work/moves things the wrong way
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