- Home /
Is there no simple way to get a device heading in Android with Unity?
Hi,
All I need is to find out how to get the direction the Android device is pointing in, for an AR app our company is looking to develop.
I will also need to access the device camera as a background to the 3d game-world, but right now I'm just starting out.
I can access the GPS of the device, so in the 3d world of the app, I place an object at certain x/z co-ordinates (multiplied by 1000 - so 35.566754 degrees latitude in real life would be 'x' co-ordinate 35566.754 in the app 3d world), and while I can sucessfully match the 3d-world camera to the real life device position, I cannot seem to match the camera to the device direction - the camera must always look at the target object - not ideal for AR purposes.
We're just prototyping at the minute, and haven't settled on a development environment yet, but we did notice Shiva can access Android compass headings quite easily with one line, see here: http://www.stonetrip.com/developer/doc/api/system-getLastKnownHeading
So if it's that simple to get the compass bearing in Shiva, why can't Unity?
The only kind of answer to this question I've seen on Unity Answers links to here: http://answers.unity3d.com/questions/43794/compass-java-plugin-for-unity-android.html
Which doesn't really help us, as the answer is psuedocode, and a bit complex for what should be a simple task of accessing a vector heading from a part of the android device.
Can anyone shed some light on a possible solution for this, or is Shiva superior for this kind of thing?
Any help appreciated.
Bratman
Answer by wiserd · Aug 10, 2011 at 08:09 PM
Prime 31 just released a plugin (costs money, but not much) to expose sensor data in the Android phone. It's not up on their website yet. As someone who's been looking for the same thing, this seems to be the best solution as of this date. At least as far as I can find.
Answer by fherbst · Sep 06, 2011 at 03:54 PM
Prefrontal Cortex also has such a plugin in the asset store, which provides access to all sensors Android has to offer.
Forum link: http://goo.gl/8ZIM7