Gyroscope error on iPhone

Hi, I’m new to Unity. I’m building a game using gyroscopes to control the camera for both Android phone sand iPhones. I’m using Unity 5.4.0f3 for iPhone, and I’m having a problem.

The problem is, when I started the game on my iPhone, sometimes the camera kept rotating while I hold the phone still, and sometimes the camera worked well.

I’m using this method for the gyro:

x = (initialOrientationX - Input.gyro.rotationRateUnbiased.x);
y = (initialOrientationY - Input.gyro.rotationRateUnbiased.y);
z = Input.gyro.rotationRateUnbiased.z - initialOrientationZ;

 transform.Rotate(x, y, z);

I think this gyro code is quite typical, but I have this weird problem.

After I tested more on this problem, i found that:

  1. It’s caused by rotating the phone while the game was been loaded. There’s a short time of black screen before the Unity splash screen shows, when I shake my phone during that black screen period, the camera would go mad when the game starts, and if I just hold the phone still while the screen is black, the camera would be fine. Even if I rotated the phone during the Unity splash screen after the black screen, the camera would be fine. So the problem should be caused by the rotation of the device during the black screen period, and it could be very annoying to me as my game use landscape mode, user would rotate their phones after launching the game…

  2. It’s not as important I guess but I still write it down. The problematic rotation of camera could have different rotation patterns. The speed and direction of the camera rotation is variable due to different rotating during the black screen period, and sometimes, it can even have fast rotation - slow rotation - fast rotation pattern.

I tried to disable the gyro and enable it later to “reset” the gyro, but it didn’t work. And I also tried to set the initial orientation a bit later after the game starts, it also failed.

I’m using Unity 4 for my game on Android platform, and the camera works fine, the problem never showed up on Android version. I don’t know whether it’s because of different devices or different Unity version.

Because I’m not very good using English, I didn’t find any resolution or even people reporting the same problem that I have, so I can only ask for help here. Thanks for your patience and your answer.

Leo

Sorry, I didn’t have the same problem, but I saw the steps u did, you a step forward than me, my Input.gyro.enabled = true; never work, or it only work once, in the first frame, then is false, what did you do to make it true and runable on your iphone?