Hello Everyone,
I am trying to understand how to use the accelerometer in an Android phone. To do this, I checked the Unity documentation and found an example. Part of the example code has a section where they remap the device acceleration axis to game coordinates. I don’t understand that concept, nor the code that goes with it. The code is as follows:
// remap the device acceleration axis to game coordinates
// 1) XY plane of the device is mapped onto XZ plane
// 2) rotated 90 degrees around Y axis
dir.x = -Input.acceleration.y;
dir.y = Input.acceleration.x;
Can someone please explain why one would want to do the “remap” and also explain the code that goes with it? Thank you in advance for time spent. This is killing me! 
I hope it’s not too late. The accelerometer gives you the reading from -1 to 1, and you might want it to use on a much larger scale. So mapping the accelerometer reading to a wider range will help you getting your work done. Hope I’m clear. 
Thank you very much for replying! I’m still not understanding the actual code though. Also, I made a mistake in my post. The line that reads dir.y = Input.acceleration.x; should read dir.z = Input.acceleration.x;. If time permits, would you mind explaining what the code is doing? I think there is some linear algebra concept I’m missing or something. Thank you!!
Okay, the accelerometer has 3 axis in the following manner
- x - tilting the phone from left - right and vice versa
- y - upside down and vice versa
- z - lifting the phone up and down
What they have done in the code is to get the x axis of the accelerometer and use it to change the dir’s z component,
and moved it with the specified speed.