How do i rotate my character's sprite according to the player velocity?

Godot Version

Godot Engine v4.4.1.stable.steam.49a5bc7b6

Question

I am making a wall movement on my game, and i want the character sprite rotate according to the player’s velocity, does anyone has any ideas on how to do it?


My code for now:

func _wall_animate():
	if Global.wallmovment:
		if character_select == Character.Sonic:
			$Sprite.play("running_wall(sonic)")
		elif character_select == Character.Shadow:
			$Sprite.play("running_wall(shadow)")
		elif character_select == Character.Super_Shadow:
			$Sprite.play("running_wall(super_shadow)")

First you come up with a ratio: how much velocity should translate to how much rotation? Then you calculate and apply the rotation based on the velocity every frame. If the rotation is an animation, then you take into account how many frames there are in the animation and set the animation speed accordingly.

It worked, thank you