Unity3D & accelerometer

stisa, Jul 8, 2014

You know that feeling when you spend ours thinking about an issue, and you finally understand something very simple was missing the whole time? Well, I know that feeling very well.

  accel : Mathf.Round(Mathf.Sqrt(
    (Input.acceleration.x *Input.acceleration.x) +  
    (Input.acceleration.z * Input.acceleration.z) +  

Outputted 0. Zero. Always, even when shaking the phone. And then I realized Input.acceleration gives a value between 0 and 1, and then rounding down that number always ended up to zero.

Next time, I might read documentation a bit more carefully, although I didn’t find it mentioned on the Unity docs.


  • Unity
  • accelerometer