- Home /
real north for a simple compass
i want to build a simple (real) compass. for that i must know the angle relative to magnetic north to rotate my compass on Y axe...
iOS has magneticHeading that is exactly what i need LINK HERE
is there any similar way to do tha same thing in unity or is possible to pass a magneticHeading from xcode as a variable to unity?
You should be able to. See the documentation page on native calls and using objective-c. I can't link to it hear.
Answer by ratdoesit · Aug 17, 2010 at 01:44 AM
thanks for you response Wolfram, i find very interesting the links from you but i don't want to build a so real compass.. :P
by real i mean a real iphone compass that is pointing to the real world north and not an ingame compass that is pointing to a game world north...
i stil don't have a solution, so, any help is welcome...
I don't have a script, but yes, you can make a native call to output the compass value. See the Unity iPhone manual for doing that. You found the reference so all's you need to do is write an obj-c file that reads the compass, then link it to your Unity project which is all explained in the Unity iPhone manual and example on that page.
Prime31 just came out with a plugin for Sensor data. I just found out from an email they sent. As of today, it's not on their website.
Answer by Wolfram · Aug 17, 2010 at 12:15 AM
What you are looking for is "magnetic declination".
Here's a map showing its dependence on location: http://en.wikipedia.org/wiki/File:Mv-world.jpg (simple version: http://en.wikipedia.org/wiki/File:IGRF_2000_magnetic_declination.gif )
Here's an online tool: http://www.ngdc.noaa.gov/geomagmodels/struts/calcDeclination
Here's some Fortran code which does the job :-D http://www.ngdc.noaa.gov/IAGA/vmod/igrf11.f
I don't think that's what he means. He is referring to the built in compass on the iPhone which has public apis that devs can use in their apps to get location and direction. He wants to know how to access that in Unity.
Oh I interpreted his question the wrong way, I thought he actually tried to find the different between true north and magnetic north, as part of an advanced compass, but he just wants to access the normal iPhone compass.
O$$anonymous$$G, it is the first time I look on Fortran code... Awful ! (I know useless comment...)
Your answer
![](https://koobas.hobune.stream/wayback/20220613071408im_/https://answers.unity.com/themes/thub/images/avi.jpg)