- Home /
Question by
PuneetK · Nov 23, 2013 at 12:37 PM ·
accelerometergyroscopetilt
Using accelorometer with device parallel to table?
I want to use the accelerometer in my game, but I want the default orientation to be parallel to the table, not horizontal. So basically, if you tilt the device backwards, move my player up, if you tilt forward, move back, and so on.
Here is the current code, which isn't working as expected
void checkAccel()
{
Vector3 dir = Vector3.zero;
dir.x = Input.acceleration.x;
dir.z = Input.acceleration.y;
if(dir.sqrMagnitude > 1)
dir.Normalize();
if(dir.x > 0)
InputIsRight();
if(dir.x < 0)
InputIsLeft();
if(dir.z > 0)
InputIsUp();
if(dir.z < 0)
InputIsDown();
}
If I hold my phone VERTICAL right now, it senses 0 input. I want this to happen for the horizontal plane.
Comment