extends CharacterBody2D const SPEED = 700.0 func get_input(): var directionX = Input.get_axis("move_left", "move_right") var directionY = Input.get_axis("move_up", "move_down") # Get the input direction and handle the movement/deceleration. if directionX : velocity.x = directionX * SPEED else: velocity.x = move_toward(velocity.x, 0, SPEED) if directionY: velocity.y = directionY * SPEED else: velocity.y = move_toward(velocity.y, 0, SPEED) #region Animation if (directionX < 0): $Skeleton2D/root/Hips.set_scale(Vector2(1, 1)) if (directionX > 0): $Skeleton2D/root/Hips.set_scale(Vector2(-1, 1)) $AnimationTree.set("parameters/WalkRun/blend_position",max(abs(velocity.x),abs(velocity.y))) #endregion func _physics_process(delta): get_input() move_and_slide()