Search Unity

Input.acceleration problem :)

Discussion in 'Scripting' started by Deleted User, Aug 15, 2012.

  1. Deleted User

    Deleted User

    Guest


    Thats my code :) It works perfect in Unity while playing through Unity Remote on Galaxy Tab.. When building an installing APK its just going FULL power left.. :p Found out if i locked the Auto Rotation on the screen, and flips the screen it changes direction...

    What am i doing wrong? :D Again works perfect playing in the Editor with Unity Remote on the tab...
     
  2. znoey

    znoey

    Joined:
    Oct 27, 2011
    Posts:
    174
    acceleration is handled differently on android devices. Unity's acceleration is based on the iOS accelerometer.
    I've found for my android devices that i need a
    Code (csharp):
    1.  
    2. var acc = Input.acceleration;
    3. #if UNITY_ANDROID
    4. var hold = acc.x;
    5. acc.x = -acc.y;
    6. acc.y = hold;
    7. #endif
    8.  
    to make sure its working right on both devices.
     
  3. gfoot

    gfoot

    Joined:
    Jan 5, 2011
    Posts:
    550
    Last time I tried it, Unity Remote didn't support the accelerometer or gyro.

    What you're seeing is probably gravity. The acceleration reading is generally aligned to the device's default (portrait) orientation, regardless of what you tell Unity in the player settings. So if you've requested a landscape orientation, you need to shuffle the axes around. So the X axis points up or down (depending which landscape orientation you used), and the Y axis points left or right. You can for example multiply by Quaternion.Euler(0, 0, 90), or -90, to get Input.acceleration transformed into view space.
     
  4. Deleted User

    Deleted User

    Guest

    It worked m8! :D Thx soo much! :D
     
  5. znoey

    znoey

    Joined:
    Oct 27, 2011
    Posts:
    174
    no problem. Be warned that i think this only works well if your not letting unity rotate your screens for you (IE: portrait, landscape left...). Or the results may seem a little unexpected.