I’m currently working on a 2D game where the player can move along the x and y axis based on the accelerometer. I’m currently using this to get that done:
Vector3 dir = Vector3.zero;
dir.x = Input.acceleration.x;
dir.y = Input.acceleration.y;
if (dir.sqrMagnitude > 1)
{
dir.Normalize();
}
dir *= Time.deltaTime;
transform.Translate(dir * speed);
What I am trying to figure out next is how to get the player to face the direction it’s tilting towards (z axis for rotation). Googled up many result but I can’t seem to find a solution.