My gyroscope doesnt work properly and i'm desperate.

I am working on a 2D platformer for android smartphones and i want to use the gyro to move the player, so that when you tilt your phone to the right, the player moves to the right. I am currently working with this:

private void FixedUpdate ()
{
// Read the inputs.
bool crouch = Input.GetKey(KeyCode.LeftControl);
//float h = CrossPlatformInputManager.GetAxis(“Horizontal”);

	float rotateFactor = 1.5f;
	float gyroSpeed_z = Input.gyro.rotationRateUnbiased.z;
		//if (Mathf.Abs (gyroSpeed_z) > 0.1f) 

        // Pass all parameters to the character control script.
	m_Character.Move(gyroSpeed_z, crouch, m_Jump);
        m_Jump = false;
    }

and this:
public void Move(float move, bool crouch, bool jump)
{
if (!crouch && m_Anim.GetBool(“Crouch”))
{
if (Physics2D.OverlapCircle(m_CeilingCheck.position, k_CeilingRadius, m_WhatIsGround))
{
crouch = true;
}
}

        m_Anim.SetBool("Crouch", crouch);

        if (m_Grounded || m_AirControl)
        {
            move = (crouch ? move*m_CrouchSpeed : move);

            m_Anim.SetFloat("Speed", Mathf.Abs(move));

            m_Rigidbody2D.velocity = new Vector3(move*m_MaxSpeed, m_Rigidbody2D.velocity.y);      						//ADDED

            if (move > 0 && !m_FacingRight)
            {
                Flip();
            }
            else if (move < 0 && m_FacingRight)
            {
                Flip();
            }
        }
        if (m_Grounded && jump && m_Anim.GetBool("Ground"))
        {
            m_Grounded = false;
            m_Anim.SetBool("Ground", false);
            m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
        }
    }

the codes are from two different scripts

and i am stuck. The player moves to the right direction (but only if i multiply gyro value by -1) when i tilt my phone but only for a short period of time, then he stands still again. It is as if the 0 value of the gyroscope is constantly reset to the current rotation of the phone. I am new to this stuff and i am sorry if you see some disturbing stuff in my code :slight_smile: May somebody help me PLEASEEEEE

You’re measuring the rotation rate, not the tilt. Your character is only moving while you’re actively spinning the phone, as it currently stands. Read the accelerometer instead and you’ll have the result you want. The gyroscope can be used for this, by reading Input.gyro.attitude, but gyroscopes are only in more expensive phones. It is more accurate, for sure, but fewer phones can use it, so it’s a tradeoff. Read this thread for more information so you can make your decision.