Model should face geographical head north.

Hi, I am working on a android application in which i will place 3d objects based in geographical location. This is working good. The problem is with rotation. Always the generated gameobject should face geographical North direction. How to do it?
I have tried

transform.rotation = Quaternion.Euler(0, -Input.compass.magneticHeading, 0);

it is not working correctly, showing wrong direction. Is there any other way gameobjects should face geographical north.

What direction does it actually face? Is there a pattern?

Assuming that the Y axis is “up” in your world, and that the object is facing towards its local Z axis, and that you are holding your phone flat (because the compass faces out the top), my guess would be that you are doing almost the right thing, but need to add and/or multiply by some constant. Since the appropriate constants depend on a bunch of details of how your game world is set up, the easiest way to figure them out is probably to reverse-engineer exactly what your current attempt is doing.

Firstly Thank you the reply. When instantiated the gameobject is facing the direction of android device. It is behaving same like this in link . Not my application
https://www.youtube.com/watch?v=GiPwxWNSd1E

Are you creating the object the moment the app starts? You might try monitoring the compass for several seconds after you enable it and see if it “settles down”. I don’t see any warnings in the documentation about this, but sometimes hardware sensors aren’t accurate the instant you turn them on.

You also might check the value of compass.headingAccuracy to see how accurate Unity thinks it is.

It might even be helpful to take several readings and average them together. I once made a game that used the compass to orient a map, and I found the map was pretty jittery until I added some time-averaging to the compass readings. (Of course, time-averaging can also make you less accurate while the phone is rotating…)