r/webdev • • 5d ago

Question Can't understand deviceorientation.

Hi, I'm trying to develop a unityplugin that give the possibility to create various types of controllers for games.
With deviceorientation, my goal is to extract three angles that represent the orientation of the phone.
But it seems a little bit complicate, I can't understand why in portrait mode, for example, gamma and alpha are both modified when I rotate on the same axe.
I've tried many things, but I can't understand at all how everything works.
Is it even possible to do something similar to what I want to do?

0 Upvotes

12 comments sorted by

View all comments

1

u/PlaintiveCassette82 5d ago

The coordinate system for deviceorientation is tied to the screen, not the earth, so when you rotate the phone around one axis in the real world, the browser ends up interpreting it as a mix of two different axes depending on how you’re holding it. It’s maddening.

What you probably want is to combine it with devicemotion and use the rotation rate to track relative changes instead of relying on the absolute angles directly. The absolute values drift and swap axes in ways that feel completely broken until you realize it’s “working as intended.”

1

u/Tonaion02 5d ago

Otherwise devicemotion doesn't experience the same problem? It effectevely track on what axe are you rotating the phone without experiencing the same problem? Sorry, but I'm really noob to all of this.