- Home /
AR Camera Rotation without gyroscope
Hello,
First, I'm sorry if my english is not very good, I'm french !
The code below come from Heyworks Unity Studio and thanks to the GyroController.unitypackage which helped me a lot with gyroscope.
Summary :
Unity 4.3.4f - C# Galaxy Tab 2 (model GT-P5110) without gyroscope Trying to rotate the camera using the compass (and anything else) on the 3 axis or 2 at the minimum (up/down & right/left).
In details :
I'm developper on Unity (in C# currently) and programming an AR application. So the application is working on the tablet with gyroscope but i have to adapt it for the tablets without gyroscope. On my Galaxy Tab 2 (GT-P5110) there is no gyroscope.
How can I rotate the camera in the 3 axis just with the compass (and any other tool if necessary) ?
I'm trying only with Compass like this :
m_camAR.transform.rotation = Quaternion.Euler(Input.compass.rawVector.y, -Input.compass.rawVector.x, 0);
This code let me turn on the up/down and right/left axis but only until I reach some values. These values are approximatively 316-317° and 43-44°, after that, the camera rotation is very strange, it goes up when i'm going to the left, etc...
I'm not very good at maths...so please forgive me if it's very simple ! Here is a screenshot when looking to the north, a little bit lower.
As you can see in the box, there is the rotation of camera and the rawVector of the compass.
So I'm searching a method to update that position which could accept the 360° rotation with that rawVector (or anything else) but without using gyroscope.
I read a lot of articles and answers and codes but didn't find the solution. It is possible because i found an app on the Play Store "3D Compass" which works (but in java).
I'm on Unity 4.3.4f.
Thanks a lot for all answers.
Answer by ejpaari · Mar 06, 2014 at 01:42 PM
I would suggest using true heading instead of raw vector so you can get a simple compass heading in degrees relative to north point. Something like this:
transform.rotation = Quaternion.Euler(0, -Input.compass.trueHeading, 0);
Nevertheless switching gyro to compass could be somewhat bad idea, because compass is not as precise or fast as gyro. Instead you could try to take advantage of accelerometer (there is a plugin for that as well: https://www.assetstore.unity3d.com/#/content/1754).
Hello,
Thanks for your answer, yes I know it's not a good idea to use compass ins$$anonymous$$d of gyro, but without gyro, I've no choice.
What you suggest is working to rotate left/right, I know it and i'll keep it if I don't find any other solution (or I'll lock the AR functionality).
Thanks for the asset, I'll watch it.
I'm glad I could help. If you think it answers to your question, you should mark it as "Answer" by clicking the little v-sign.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Mathf.pingpong 4 Answers