Imagine that the user is holding the device with both hands in landscape mode. I need to determine the roll / tilt angle. The picture below show three different angles.
This is the only kind of rotation I am interested in. So I tried using Input.gyro.attitude.eulerAngles.z
. That works if the forward vector of the gyroscope is pointing at the horizon like the top image below. But if the forward vector is pointing downwards (3rd image) it fails.
So I was wondering if anyone has an idea of how to determine the angles (z rotation) shown in the first image regadles of x rotation. I know that this a typical case of gimbal lock, but there must be a work-around. How do racing games tackle this problem when using the gyro for steering??
Note: I do not want to use Input.gyro.rotationRate
and apply it as a delta to some kind of starting orientation, because that will become more and more inaccurate over time. Input.gyro.attitude
(which is a quaternion) is the way to go. I just don’t know how to get roll / tilt if the device is facing down (or up).
Where can I find information about the DeviceRotation.Get()? The content on the website you have posted the link to seems to have changed. Thanks!
– DexterOh thanks for that! Do you know how I could modify this to get only the values of the z axis?
– DexterThat's what the code in the original answer is for :)
– CredendumHow can I calculate pitch instead? Sorry, but I dont understand quaternions at all
– Dewaynedewberry@Credendum Is GetRotation() the same as Get() ?
– Harken