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)