I only took a brief look at the script, but something like the following should fix the flip_h
issue and add gravity/jumping:
extends KinematicBody2D
const GRAVITY = -100
const JUMP_SPEED = 300
const SPEED = 750
var velocity = Vector2()
var movement = Vector2()
func _physics_process(delta):
var direction = Vector2(0, 0)
if Input.is_action_pressed("ui_right"):
direction.x += 1
$AnimatedSprite.play("run")
if Input.is_action_pressed("ui_left"):
direction.x += -1
$AnimatedSprite.play("run")
if Input.is_action_pressed("ui_up"):
velocity.y += JUMP_SPEED
$AnimatedSprite.play("jump")
if direction == Vector2(0, 0): # Is still
$AnimatedSprite.play("idle")
# Flip the sprite so it looks in the correct direction
if direction.x > 0:
$AnimatedSprite.flip_h = false
elif direction.x < 0:
$AnimatedSprite.flip_h = true
velocity += movement * SPEED
velocity = move_and_slide(movement)
I have not tested the code, but I think it should work.
(Side note: welcome to the forums!)