I'm trying to assign different animations to movements of a Player character. However, I'm facing some sort of issue in my code: writting "else: _animated sprite.stop()" to every individual line appears to cancel the animations all together, whilst writting it in single line allows only one of the animations to play.
extends KinematicBody2D
export (int) var speed = 200
onready var animatedsprite = $AnimatedSprite
var velocity = Vector2()
func get_input():
velocity = Vector2()
if Input.is_action_pressed("ui_right"):
velocity.x += 1
_animated_sprite.play("Right")
else:
_animated_sprite.stop()
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
_animated_sprite.play("Left")
else:
_animated_sprite.stop()
if Input.is_action_pressed("ui_down"):
velocity.y += 1
_animated_sprite.play("Forward")
else:
_animated_sprite.stop()
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
velocity = velocity.normalized() * speed