Comments and answers for "Gyroscope steering - set default position of phone"
http://answers.unity.com/questions/951820/gyroscope-steering-set-default-position-of-phone.html
The latest comments and answers for the question "Gyroscope steering - set default position of phone"Answer by campeanionut93
http://answers.unity.com/answers/1590445/view.html
I know this is an old question, but maybe somebody else stumbles upon this.
You might want to look into Input.gyro.gravity. That returns a Vector3 with the real world gravity that is applied to each axis, in the range [0, 1] (where 0 is no gravity i.e. the axis is perpendicular on the gravity vector, and 1 is full gravity i.e. the axis is aligned with the earth's gravity vector).
For example, if you hold your phone like in picture 1, the gravity on the Y axis (top to bottom of your phone, depending on orientation) would be 0. In picture 2, assuming you hold your phone at a 45 degree angle, the gravity value for Y would be sine(45 deg) ~= 0.7.
If we apply some simple trigonometry (search google for the trigonometric circle and sine function), we basically want to offset the graph of the sine function. Since we know that Input.gyro.gravity.y is the sine of the y axis angle relative to the gravity vector, we can do this:
float NormalizeGravity(float axisValue, float defaultRotationInDegrees)
{
return Mathf.Sin(Mathf.Asin(axisValue) + Mathf.Deg2Rad * defaultRotationInDegrees);
}
**DISCLAIMER: I tested this in landscape mode. You may also need to take care of the sign of the Sin and Asin functions.**Tue, 15 Jan 2019 15:53:53 GMTcampeanionut93