- Home /
Rotate objects towards gps coordinates
I want to rotate a 2D object towards specific real life GPS coordinates, which I can set (not the devices coordinates, rather any coordinates I type into the code. i.e. I dont need a UI to set it, I only want something like
float latitude;
float longitude;
which I can edit to hold any coordinates).
The app should work that when I rotate myself/device a 2D object rotates to always face the specific aforementioned coordinates.
Heres the code I have so far, which rotates a 2D object to always face forward, no matter the rotation of my phone.
Gyroscope gyro;
void Start () {
//checks if the gyroscope is enabled
gyro = Input.gyro;
if(!gyro.enabled)
{
gyro.enabled = true;
}
}
void Update ()
{
//makes sure that the screen doesnt rotate if phone is rotated,
//even if auto rotate is on in phone settings, to ensure proper functionality.
Screen.autorotateToLandscapeLeft = false;
Screen.autorotateToLandscapeRight = false;
Screen.autorotateToPortraitUpsideDown = false;
//The actual rotation code
transform.Rotate (0, 0, -Input.gyro.rotationRateUnbiased.z);
}
Im really new at Unity, so please answer very clearly.
Thanks!
Your answer
Follow this Question
Related Questions
How can I rotate a 3d object along a direction? 0 Answers
How can I rotate an object without moving it up or down? 0 Answers
Rotating object within bounds using gyroscope 1 Answer
Using Gyroscope with Android 1 Answer
Change Gyroscope forward 1 Answer