Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Compass magneticHeading problem in portrait mode (Android)

Discussion in 'Scripting' started by atreyu64, Jan 24, 2018.

  1. atreyu64

    atreyu64

    Joined:
    Feb 12, 2017
    Posts:
    6
    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
     
    R0man likes this.
  2. Marek_Bakalarczuk

    Marek_Bakalarczuk

    Joined:
    Dec 28, 2012
    Posts:
    114
    Try

    Code (CSharp):
    1. transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, Input.compass.trueHeading, 0), Time.deltaTime * 2);
     
  3. atreyu64

    atreyu64

    Joined:
    Feb 12, 2017
    Posts:
    6
    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.
     
  4. Marek_Bakalarczuk

    Marek_Bakalarczuk

    Joined:
    Dec 28, 2012
    Posts:
    114
    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.
     
  5. EvanKnowles

    EvanKnowles

    Joined:
    Dec 10, 2015
    Posts:
    3
    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?
     
  6. atreyu64

    atreyu64

    Joined:
    Feb 12, 2017
    Posts:
    6
    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 !
     
  7. R0man

    R0man

    Joined:
    Jul 10, 2011
    Posts:
    90
    I guess filing a bug report is out of the question.
     
  8. AbleArcher

    AbleArcher

    Joined:
    Feb 27, 2017
    Posts:
    9
    If your phone is pointed straight up, are you not pointing equally south, north, east, and west?
     
  9. atreyu64

    atreyu64

    Joined:
    Feb 12, 2017
    Posts:
    6
    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.