How rotate the player in the correct angle

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By loml666

I am trying to rotate the player by code to correct angle pressing a key.

	if Input.is_action_pressed("ui_right"):
	rotation_dir += 1
if Input.is_action_pressed("ui_left"):
	rotation_dir -= 1
if Input.is_action_pressed("ui_down"):
	velocity += -transform.basis.z * speed
if Input.is_action_pressed("ui_up"):
	velocity += transform.basis.z * speed

    #rotate the player  in 0,90,-90,180

if Input.is_key_pressed(KEY_M):
	if rotation_degrees.y>0 and rotation_degrees.y<90:
		rotation_degrees.y=0
	if rotation_degrees.y>90 and rotation_degrees.y<180:
		rotation_degrees.y=90
	if rotation_degrees.y>-180 and rotation_degrees.y<-90:
		rotation_degrees.y=-90
	if rotation_degrees.y>-1 and rotation_degrees.y>-90:
		rotation_degrees.y=0
rotation.y += rotation_dir * speed * delta
velocity = move_and_slide(velocity)
:bust_in_silhouette: Reply From: juppi

You could calculate the rotation degrees based on the player’s movement direction.
Take a look at the Godot Docs:
https://docs.godotengine.org/en/stable/tutorials/math/vector_math.html