Search Unity

Question Tutorial for Input System and Accelerometer / Gyro?

Discussion in 'Input System' started by Kmil81, May 11, 2020.

  1. Kmil81

    Kmil81

    Joined:
    May 5, 2019
    Posts:
    9
    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.
     
    makaka-org likes this.
  2. Kmil81

    Kmil81

    Joined:
    May 5, 2019
    Posts:
    9
    Has anyone had any success getting motion control (accelerometer or gyro) working with the new input system?
     
    crumby_shirt likes this.
  3. GamezAtWork

    GamezAtWork

    Joined:
    Jan 12, 2013
    Posts:
    3
    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.
    Code (CSharp):
    1.  
    2. if (UnityEngine.InputSystem.Gyroscope.current != null)
    3. {
    4.        InputSystem.EnableDevice(UnityEngine.InputSystem.Gyroscope.current);
    5. }
    6. if (AttitudeSensor.current != null)
    7. {
    8.         InputSystem.EnableDevice(AttitudeSensor.current);
    9. }
    10.  
    Then when you need it, I called it like this:

    Code (CSharp):
    1. UnityEngine.InputSystem.Gyroscope.current.angularVelocity.ReadValue();
    2. AttitudeSensor.current.attitude.ReadValue();
    Definitely not ideal, but I hope it helps!
     
  4. HosseinSrz

    HosseinSrz

    Joined:
    Jun 24, 2016
    Posts:
    18
    That's worked!
    Thanks :)
     
  5. crumby_shirt

    crumby_shirt

    Joined:
    Oct 13, 2013
    Posts:
    3
    TheyCallMeTJ likes this.
  6. noemis

    noemis

    Joined:
    Jan 27, 2014
    Posts:
    76
    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.