Setting start position for gyroscope on iphone in unity3d

0 Votes
    1319 Views

Having issues setting the starting gyroscope position while using it to control X/Y axis.
I’ve tried using input.gyro.attitude (as per the commented out parts below, and I’m kind of stuck.
Any advice would be greatly appreciated!

Thank you.

public class PlayerController : MonoBehaviour {

    private float InitialOrientationX;
    private float InitialOrientationY;
}
    void Start ()
        {
    Input.gyro.enabled = true;
            //InitialOrientationX = Input.gyro.attitude.x;
            //InitialOrientationY = Input.gyro.attitude.y;
    }

        if (SystemInfo.deviceType == DeviceType.Handheld) 
                {
                    float moveHorizontal = Input.acceleration.x;
                    float moveVertical = Input.acceleration.y;                        
                    // take initial gyro readings from initialorientation* and subtract position moved to get more accurate reading without having to lie phone flat
                    Vector3 movement = new Vector3 (moveHorizontal, 0.0f,moveVertical);
                    //Vector3 movement = new Vector3 (InitialOrientationX - Input.gyro.attitude.x, 0, InitialOrientationY - Input.gyro.attitude.y);
                    // add a little force to the player movement (not technically accurate in realworld physics. 2* to begin with?
                    rb.AddForce (movement * speed * 2);
                } 

Please signup or login to answer this question.