Sprite follow mouse cursor

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

Hey, my character moves on the keys wasd, but I wanted to implement a system for him to look at the mouse cursor as well and his attacks follow where the cursor apoint.
It has some animations like idle (left, righ, top, down) and run (left, right, top, down).
The code:
`func _physics_process(delta):
match state:
MOVE:
move_state(delta)
ATTACK:
attack_state(delta)
func _ready():
mouse_pos = get_local_mouse_position()
func move_state(delta):

var input_vector = Vector2.ZERO
input_vector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
input_vector.y = Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up")
input_vector = input_vector.normalized()
if input_vector != Vector2.ZERO:
	animatedSprite.set("parameters/Idle/blend_position",input_vector)
	animationTree.set("parameters/Idle/blend_position",input_vector)
	animationTree.set("parameters/Run/blend_position",input_vector)
	animationTree.set("parameters/Attack/blend_position",input_vector)
	animationState.travel("Run")
	velocity = velocity.move_toward(input_vector * MAX_SPD, ACCELERATION * delta)
else:
	animationState.travel("Idle")
	velocity = velocity.move_toward(Vector2.ZERO, FRICTION * delta)


velocity = move_and_slide(velocity)


	

if Input.is_action_just_pressed("attack"):
	state = ATTACK

func attack_state(delta):
animationState.travel(“Attack”)
func attack_animation_fineshed():
state = MOVE `

:bust_in_silhouette: Reply From: klaas

Hi,
like so … ?

player.look_at( mouseposition )

read about it here …

but if i do this, the sprite rotates, i want to change de sprite animation(mouse on left → idle left)

veiran2010 | 2020-08-26 13:49