Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | RiqueDiaz |
I’am trying to make a click to move type of movemment, and just for test i added only 2 animations for walking and idle. The wlaking animation works in both right and left direction, but it doesn’t stops even when the player is not moving. I think it is not processing when the velocity is 0, because i even use a print code when the velocity in x and y are 0, but it also does nothing when the player stops.
var speed = Vector2(200, 200)
var last_mouse_pos = null
func _input(event):
if event.is_action_pressed("mouse"):
last_mouse_pos = get_viewport().get_mouse_position()
func _physics_process(delta):
if last_mouse_pos:
var direction_vector = (last_mouse_pos - global_position)
if direction_vector.length() < 3:
return
var velocity = move_and_slide(direction_vector.normalized() * speed)
if velocity.x && velocity.y > 0:
$AnimationPlayer.play("frente")
if velocity.x && velocity.y < 0:
$AnimationPlayer.play("frente2")
if velocity.x && velocity.y == 0:
$AnimationPlayer.play("neutro")