How to rotate an object to face the direction of the accelerometer in 2D

So I have a player object that I am moving according to the accelerometer with this code:

transform.Translate(Input.acceleration.x * speed, Input.acceleration.y * speed, 0);

I want it to rotate to the direction that it is travelling, I can’t do this with a vector3 because I’m not using one for the movement. The basic idea would be for the player to tilt the screen left (in landscape) and for the player object to rotate so that the front of the object also faced left. I have been looking for ways to do this for a while now but I’m still stuck. Any help is appreciated :slight_smile:

Instead of setting the rotation directly, you could lerp towards it by some factor, e.g. 0.5.

transform.localEulerAngles = Vector3.Lerp(transform.localEulerAngles, targetRotation, 0.5f);

Well somehow I have managed it…

That question helped a lot so if you are having similar problems look at that :slight_smile: