Need to get a reading from the android compass, with unity

Can Unity determine the direction an Android device is heading?

We are looking to develop an Android/iPhone augmented reality project, and are currently trying to decide whether to use Unity or Shiva to develop it. I found that the compass is easily read with Shiva in this simple call:
http://www.stonetrip.com/developer/doc/api/system-getLastKnownHeading
I was hoping that it would be this simple with Unity, but so far I can find little information on sensor based augmented reality with Unity.

We were hoping to match a camera in the virtual world, to the rotation/tilt of the device, using the accelerometer and compass, combined with gps for camera position in the game world. The idea is to allow users to walk around an object placed at certain gps co ordinates, and see a 3d object overlaid on the camera video feed - so it looks like the 3d object is in the world in front of the user, who can explore it from different angles by walking around in the real world and looking through the android device.

So far the GPS access is helpful in positioning the camera, but without knowing the device’s direction we have no way to point the camera in the right place.

I was also wondering how to match the camera’s rotation to the accelerometer data (for looking up/down the object) - if anyone could provide information on this it would also be helpful,

If you think that getting the compass heading and using the accelerometer to rotate the camera are impossible to do with Unity for Android please let me know - we haven’t decided if we will use Unity or Shiva yet for the project, and still have some trial time left to decide which one would be more convenient to develop with.

Any help appreciated.

let me google that for you

1 Like

Thanks, I have seen that post, but I was hoping that there would be something as simple as the line used by Shiva, in the months since and given the newer versions of Unity released since that item you linked was posted.

I guess I’ll try using that one - is it in fact psuedocode there or is that useable as is?

It would be nice if it were exposed in Unity, but it isn’t. However it is entirely possible to get that data/

I wouldn’t make your choice of game development tools based on the availability of the compass data.

What I guess will be the sticking point is not compass at all, but gyroscopes. Last time I checked they are only available on a few android phones and they provide much better orientation data than accelerometers.

I’d check out something like layar to get an idea of what is possible

Yea, gyroscopes would make it much easier to do AR and hopefully a lot more devices will have them in the near future. I’m hoping that the accelerometer can at least in some way fill in this role.

Thanks.

I have developed an AR cameras for Unity using an accelerometer or gyro.
Researchers say that it works on 90% of devices.