Compass magneticHeading problem in portrait mode (Android)

Hi,

I am observing some weird behaviour of the compass magnetic heading value. When I hold the phone on landscape mode everything’s fine, but In portrait mode I have noticed some strange things…

When the phone is in portrait mode and held vertically (something like : -0.1< phone pitch < 0.1), the compass goes totally crazy… (meaning that I get wrong and very jerky values).

I have already submitted a question there with more details, but with no answer for now :
https://answers.unity.com/questions/1441113/compass-magneticheading-problem-in-portrait-mode-a.html

Could it be a Unity bug during the computation of magneticHeading and trueHeading from raw sensor data ?

Or am I missing something ?

Should I try to compute the magnetic heading on my own from rawVector and phone orientation or is it too complex ?

Thanks in advance for your answers,

Sylvain

1 Like

Try

transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, Input.compass.trueHeading, 0), Time.deltaTime * 2);

Hi, thanks for your reply.
I’ve just tried your suggestion, and it leads to the same problem.
It’s not very surprising as the bug comes from the Input.compass.trueHeading value itself.

I tried using Input.accelerometer, but my sensor always jitter. That is why I’m not using device accelerometer, locking it in certain orientation anf lerping trueHeading with deltaTime.

I’m seeing the same issue - fine when flat, random when held up. The only other major reference I’m seeing is your own StackOverflow issue atreyu - did you find a solution?

Hi, no unfortunately I did not find any solution. I gess that reading raw sensor data and calculating by yourself the magnetic heading value could work, but personally I don’t know how to compute this value.
Please let me know if you find any information about this problem. Thanks !

I guess filing a bug report is out of the question.

If your phone is pointed straight up, are you not pointing equally south, north, east, and west?

No problem when the phone is pointed straight up, the bug occurs when “-0.1< phone pitch < 0.1”, like if you take a selfy for example.