I am new to programming and just developing my first little 2D Platformer game. I made a little character as an Kinematic Body 2D with 4 Animations: idle-right, idle-left, running-right and running-left. I wanted to make the Character playing the running Animation if you press the Arrowkeys and if not playing the idle animation and looking into the direction where you move to. The problem is that it works fine if you move left, but if you move right it is always playing the idle Animation, also if you move.
This is my player Code:
extends KinematicBody2D
var speed = 90
var left = true
....
func _process(delta):
move_and_collide(Vector2(0, 100) * delta)
if Input.is_action_pressed("ui_left"):
move_and_collide(Vector2.LEFT * speed * delta)
$AnimatedSprite.animation = "leftrun"
left = true
if Input.is_action_pressed("ui_right"):
move_and_collide(Vector2.RIGHT * speed * delta)
$AnimatedSprite.animation = "rightrun"
left = false
if !Input.is_action_just_pressed("ui_right") && !Input.is_action_pressed("ui_left") && left == true:
$AnimatedSprite.animation = "left"
if !Input.is_action_just_pressed("ui_right") && !Input.is_action_pressed("ui_left") && left == false:
$AnimatedSprite.animation = "right"