Gyroscope controls ufo game?
I'm very new to Unity and I've just finished the Ufo Game. (https://unity3d.com/learn/tutorials/projects/2d-ufo-tutorial)
I'm trying to make it use gyro settings for android, however I can't seem to get it to work.
I've had a look around and cant find a code to help, if anyone can help that would be amazing.
At the minute my code is this, which doesn' work:
void FixedUpdate () { if (Input.gyro.enabled) { Input.gyro.enabled = true; float initialOrientationX = Input.gyro.rotationRateUnbiased.x; float initialOrientationY = Input.gyro.rotationRateUnbiased.y; rb2d.AddForce(new Vector2 (initialOrientationY * speed, initialOrientationX * speed)); } else { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector2 movement = new Vector2(moveHorizontal, moveVertical); rb2d.AddForce(movement * speed); } }
Your answer
Follow this Question
Related Questions
Gyroscope Samsung S7 doesn't work properly 4 Answers
Gravity on Android 1 Answer
Input.gyro seems not working on android 8.1 0 Answers
[Gyro] unexpected rotations and offset 2 Answers
Control Camera Rotation with Mobile Device Gyroscope 2 Answers