The code works fine in theses steps: in the scene, the player is idle state when I pressing the left and right works too. The problem When I dont touch the keys is still walking, so dont clear the last state and do not set back the initial state which is idle state
here is
extends KinematicBody2D
const SPEED = 108
var motion = Vector2()
onready var animation = $AnimationPlayer
func ready():
animation.play("idle")
func _physics_process(delta):
if Input.is_action_pressed("UI_RIGHT") or
Input.is_action_pressed("UI_LEFT"):
motion = move_and_slide(motion)
else:
motion = Vector2()
func _process(delta):
var right = Input.is_action_pressed("UI_RIGHT")
var left = Input.is_action_pressed("UI_LEFT")
if right:
$Sprite.flip_h = false
animation.play("right")
motion.x = SPEED
elif left:
$Sprite.flip_h = true
animation.play("left")
motion.x = -SPEED
else:
animation.play("idle")
motion.x = 0
