How do I rotate a 2D object based on it's velocity?

Hello everyone,

I am working on a 2D game and I am trying to get my character to rotate based on its velocity. An example of the effect that I am trying to get can be seen in this video: Geometry Dash - Stereo Madness - All Coins - YouTube

Quaternions and rotation in general are a bit over my head, and trying to map rotation to the characters velocity makes it even more difficult. Can someone help me out?

The following code assumes that the front side of your sprite is pointing right when the rotation is (0,0,0).

function FixedUpdate() {
var dir = rigidbody2D.velocity;
var angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
rigidbody2D.MoveRotation(angle);
}

No Quaternions involved :slight_smile: