Most modern phones and tablets have various sensors (e.g. gyroscopes, accelerometers and/or magnetometers) for determining the orientation of the device. The use of these sensors can greatly enhance the user experience of an app, whether it is a FPS, a racing game or a digital compass.
With this script, you can skip the tedious vector calculus and quaternion analysis, and directly start adding some twist to your game:
* Full 360 degree gyroscope control;
* For older devices, without gyroscope, the accelerometer can be used to determine rotations around x and z (not y);
* Use the magnetometer to find the magnetic heading / magnetic north, independently of the device's roll and pitch;
* Automatically set a heading, pitch and/or roll to the gameobjects of your choice;
* Works in all device orientations;
* Horizon's pitch can be adjusted, so the device can be held at a convenient angle;
* Various demo scenes are included: simple character controller, turret, car and compass;
* As a bonus: easily add Joysticks, Touchpads, Buttons and Textures as a GUI for your game. These GUI elements are drawn directly to the screen, using unity’s superfast low-level
graphics library (GL);
* Use the inspector to easily setup all settings, or use new commands, like GetRotation(), SetHeading() or SetPitchOffset() to create your own custom gameplay.
[Successfully tested on various iOS devices; This asset might also work for Android, but this has not been tested]
[This asset uses some textures, audioclips and meshes originally published under Creative Commons CC0 1.0 Universal (CC0 1.0); See Third-Party Notices.txt file in package for details]
[See the readme file for contact info]
Note: At this moment there's a bug in the Unity Remote 5 App [v2.0], that prevents the correct working of the gyroscope in iOS 13 and iPadOS 13 while using the remote app. For the time being: execute your app directly on an iOS 13 and/or iPadOS 13 device, through an Xcode build.