Input.acceleration returning 0 values

I ran into a trouble while trying to add an accelerometer input in my game. This is the only trouble in my code, I think it’s correct, yet it always returns a 0

void Update()
{
      _camera.transform.rotation = Quaternion.Euler(new Vector3(Tilt().x, Tilt().y, 0));
}
private Vector3 Tilt()
{
        Debug.Log(Input.acceleration.x + ", " + Input.acceleration.y + ", " + Input.acceleration.z);
        return Input.acceleration;
}

I already tried running the build on multiple android phones, checked that the phone’s accelerometer is working using Sensor Test app, made sure the accelerometer frequency in the project settings isn’t 0 (it’s 60)

I wonder if there could be any settings that I missed? Or perhaps is this not the correct way to get the accelerometer input at all? Please help.

1 Like

I think in Unity the values are in the range of -1 to 1 and so you may not have much effect with your current code. Try multiplying the values by 10.

Also, if wanting to rotate the camera you may find it’s better to use the Gyro instead of the accelerometer.

ah I see, but even then shouldn’t the debug be at least showing a value like 0.01 instead of 0?

I tried gyro but apparently not all phones have gyro sensor, so I wanted to make it more accessible by using acceleratometer instead

I had the same problem.
Some threads suggest changing the accelerometerFrequency in the ProjectSettings.asset or setting Input.gyro.enable = true.
Nonetheless neither gyroscope nor accelerometer did return any values in my build. In the end this is what worked for me: Sensor Support | Package Manager UI website

Initialized sensor via:

InputSystem.EnableDevice(Accelerometer.current);
Accelerometer.current.samplingFrequency = 60f;

Reading values via:

Accelerometer acc = Accelerometer.current;
Vector3 tilt = acc.acceleration.ReadValue();
1 Like