- Home /
Individual rotations with gyro and compass
Hi
We have a problem when trying to rotate on two axis. The input for these rotations comes from the iPhone gyroscope and compass. What we want to achieve is rotating the phone up and down while making the unity camera aligned to the angle of the phone with the gyroscope. But also rotate around yourself making the unity camera rotate on the y-axis using the compass.
The solutions we have tried are these:
y-axis rotation (rotating the parent of the camera)
Vector3 ParentRotation = Parent.transform.eulerAngles;
ParentRotation.y = Input.compass.trueHeading;
Parent.transform.eulerAngles = ParentRotation;
x-axis rotation (on the camera)
Vector3 newAngles = transform.localEulerAngles;
newAngles.x = 180*Input.gyro.gravity.y;
transform.localEulerAngles = newAngles
or
x-axis rotation (on the camera)
Vector3 newUp = transform.up;
newUp.x = 0;
newUp.z = -Input.gyro.gravity.z;
transform.up = newUp;
The problems we are facing is that if we use the transform.up solution we only get the up/down rotation even though the angle on the parent is actually changing, but for some reason it is not actually rotating in the scene.
the transform.localEulerAngles solution only rotates up/down in some angles while the y-axis parent rotation works fine.
Any ideas on how to approach this?
Have you tried with using a combination? transform.up for Z and transform.eulerAngles for y-axis ?
Your answer
Follow this Question
Related Questions
Android Gyro explanation? 2 Answers
real north for a simple compass 2 Answers
Using gyroscope to get forward backward acceleration 1 Answer
Obtaining and Filtering Gyroscope/Accelerometer Data 1 Answer
Gyroscope based First person controller 0 Answers