I am making an game where I need to know if the phone is tilted upward (towards sky) or tilted downwards (towards ground) when in landscape.
I have used this answer Answer Link as my starting point. But when app is in landscape orientation , phone perpendicular to the ground gives value 0 and tilting it upwards or downwards give value 90. Due to this I can't determine if user has tilted phone upwards or downwards.
If anyone wants to know how I am implementing my sensor then he can ask for it but I think this much context would be enough to understand the problem.
This is how I reached the correct solution. First I made an abstract class to be used with multiple sensors (learned from Phillip Lanckner Youtube)
These are two sensor required to get the exact orientation of phone in 3D plane.
Implementation in the viewModel
extension function to convert rad into degrees
Phillip Lackner Video can be used to learn sensor management in detail and computing the device orientation can be learned further more in android docs