I am building a infinite vertical platformer for mobile platforms using Unity3D. I am using the accelerometer to move the character left and right on the screen.
if (Input.acceleration.y > -0.2f && Input.acceleration.y < 0.2f) {
maxSpeed = 17;
}
if (Input.acceleration.y > -0.5f && Input.acceleration.y < -0.2f) {
maxSpeed = 25;
}
if (Input.acceleration.y > 0.2f && Input.acceleration.y < 0.5f) {
maxSpeed = 25;
}
if (Input.acceleration.y > -0.7f && Input.acceleration.y < -0.5f) {
maxSpeed = 25;
}
if (Input.acceleration.y > 0.5f && Input.acceleration.y < 0.9f) {
maxSpeed = 25;
}
if (Input.acceleration.y < -0.9f) {
maxSpeed = 40;
}
if (Input.acceleration.y > 0.9f) {
maxSpeed = 40;
}
Basically the farther the device is tilted the faster the character moves. I'm pretty sure there is a way better way to write this code but I'm pretty terrible at math and I can't figure it out. Any suggestions on cleaning this up a bit?