rotation is back to 0 after not pressing keys

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

the $Aim is an arrow that rotates based on the player movement, i wanted to make the player to keep facing the direction of the last key pressed
but the rotation went back to zero again after releasing any keys

func get_input():

var input_direction = Input.get_vector("left", "right", "up", "down")
$Aim.rotation = input_direction.angle()
:bust_in_silhouette: Reply From: al1f

get_vector returns a vector from the actions given. If none of the actions are pressed, you will get (0,0). I would suggest adding an if statement before setting the rotation:

func get_input():
	var input_direction = Input.get_vector("left", "right", "up", "down")
	if input_direction != Vector2.ZERO:
		$Aim.rotation = input_direction.angle()

omg thank you so much youre a life saver

condair9999 | 2023-06-18 09:03