func _physics_process(delta):
var x_input = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
if x_input != 0:
$AnimationPlayer.play("run")
motion.x += x_input * ACCELERATION * delta
motion.x = clamp(motion.x, -MAX_SPEED, MAX_SPEED)
sprite.flip_h = x_input < 0
else:
$AnimationPlayer.play("idle")
motion.y += GRAVITY * delta
if is_on_floor():
if x_input == 0:
motion.x = lerp(motion.x, 0, FRICTION)
if Input.is_action_just_pressed("ui_jump"):
motion.y = -JUMP_FORCE
else:
$AnimationPlayer.play("jump")
if Input.is_action_just_released("ui_jump") and motion.y < -JUMP_FORCE/2:
motion.y = -JUMP_FORCE/2
if x_input == 0:
motion.x = lerp(motion.x, 0, AIR_RESISTANCE)
motion = move_and_slide(motion, Vector2.UP)