- Home /
Getting X axis input from accelerometer when mobile device is held upright?
Hi all! I'm developing a mobile game with a gyroscopic, VR-style camera, which rotates to face wherever the player is pointing their device. I've got this up and running the way I want it with devices containing a gyroscope sensor (so Apple devices are behaving nicely), however I ideally would like this game to be available to Android users, and I'm aware that most current Android devices do not have gyroscope sensors.
What I've been trying to do in light of this is make an accelerometer-controlled camera which achieves a gyroscopic-like effect. I've been able to achieve good results along the camera's x axis using accelerometer input, so the camera nods up and down as the player tilts the device in a very similar way to a gyroscopic camera. However, I've hit a wall as I'm trying to now implement movement along the camera's y axis when the player tilts the device left and right.
The problem is that when the device is held upright, so that the screen is directly in front of the player's face, and is then tilted from side to side, I notice that the input vector3 from the accelerometer does not change significantly. The same is also true when the device is lying flat and being rotated in a circle like a steering wheel.
What I wanted to know is if there is any way I can rotate the camera along its y axis according to the side to side rotation of the device when it is held upright, or is the lack of input from the accelerometer in this scenario just an inherent limitation of accelerometers?
I've attached some diagrams on what I'm trying to achieve and my script, if anyone has any suggestions and/or knows what is and isn't possible with an accelerometer, I would be very appreciative :)
void Update()
{
transform.rotation = Quaternion.LookRotation(new Vector3(-Input.acceleration.y, Input.acceleration.z, -Input.acceleration.x));
}
[1]: /storage/temp/77924-unity-diagram.png
Answer by escfoe2 · Apr 17 at 11:52 AM
Coming on 6 years no answer. Guess I'll give it a go. The Accelerometer measures acceleration by using tiny springs and essentially measuring the force applied to them, whereas a gyroscope uses a spinning gyro to measure the changes to the gyro over time.
Since accelerometers measure acceleration, they also measure the force of gravity (9.8m/s^2). Any axis parallel to the gravitational pull of the earth, when moved, will show almost no effect. It's an unfortunate limitation of accelerometers.
Your answer
Follow this Question
Related Questions
How can I get the movement when a mobile device moves parallel to the ground? 2 Answers
accelerometer video 0 Answers
How to calibrate the mobile gyroscope ? 1 Answer
How to judge intensity of shaking in android phones 1 Answer
Changing origin of cooridinates to decieve gyroscope in ARCore 0 Answers