I am making a platform game for mobile in Unity and I would like to increase the speed of my character the farther he travels along the x-axis, up until a max speed, using the accelerometer.
Right now I have this:
void FixedUpdate ()
{
Vector2 direction = Vector2.zero;
direction.x = Input.acceleration.x * horizontalSpeed;
if ( direction.sqrMagnitude > 1 )
{
direction.Normalize();
}
direction *= Time.deltaTime;
transform.Translate(direction);
}
Currently, the character is always moving at the same speed. How can I increase the character’s velocity the farther the device is tilted?
I’m thinking I could measure the position of the accelerometer and as the position changes, I could adjust the speed variable. I just can’t figure out how to measure it.