Tutorial for Input System and Accelerometer / Gyro?

I’ve been messing with the new input system for a week and can’t get anything related to the accelerometer, gyro, or linearacceleration input to work.

I’ve been through the docs, tried the sample code, and nothing seems to work.

I have no issues with keyboard or mouse inputs but can’t for the life of me get anything related to the motion of a mobile device to work.

Does anyone have a tutorial specific to mobile motion inputs they could share?

Thank you for your help.

1 Like

Has anyone had any success getting motion control (accelerometer or gyro) working with the new input system?

1 Like

Hi!

I admit I’m having a craptonne of problems trying to get it to work properly too (been trying to hook up the Attitude), I can’t make the InputActions trigger at all.

However, if it helps, I found out how to poll for the attitude and gyro.

First, on Start or something, you need to enable the device. I enabled both in my case because I was trying to make it work.

if (UnityEngine.InputSystem.Gyroscope.current != null)
{
       InputSystem.EnableDevice(UnityEngine.InputSystem.Gyroscope.current);
}
if (AttitudeSensor.current != null)
{
        InputSystem.EnableDevice(AttitudeSensor.current);
}

Then when you need it, I called it like this:

UnityEngine.InputSystem.Gyroscope.current.angularVelocity.ReadValue();
AttitudeSensor.current.attitude.ReadValue();

Definitely not ideal, but I hope it helps!

11 Likes

That’s worked!
Thanks :slight_smile:

1 Like

I found that it’s documented that all sensors are disabled by default - Sensor support | Input System | 1.0.2

2 Likes

This helped me also to get started with new input system, but at the end I could not get it working on android and ios… there is another thread about this topic and here’s the link to my answer there.