extends Node2D var speed = 0 var health = 0 var shield = 0 var damage = 0 var current_health = 0 var current_shield = 0 var last_position: Vector2 = Vector2.ZERO # To store the previous position func _ready() -> void: last_position = get_parent().position set_character_data() adjust_health_bar() func _process(delta: float) -> void: move_character(delta) func move_character(delta: float) -> void: var path_follow = get_parent() # Update the progress and prevent rotation path_follow.set_progress(path_follow.get_progress() + speed * delta) path_follow.rotation = 0 #turn the character to to the way its headed var current_position = path_follow.position if current_position.x < last_position.x: path_follow.scale.x = -abs(path_follow.scale.x) else: path_follow.scale.x = abs(path_follow.scale.x) # Update the last_position for the next frame last_position = current_position #if reached the end of the path remove both the path, and the character if path_follow.get_progress_ratio() >= 0.999: get_parent().get_parent().get_parent().decrease_life(damage) get_parent().queue_free() func set_character_data(): match self.name: "Forkman": speed = 120 health = 100 shield = 100 damage = 2 "Ork": speed = 80 health = 150 shield = 100 damage = 5 "Cobold": speed = 200 health = 50 shield = 0 damage = 1 get_node("CharacterBody2D/AnimatedSprite2D").speed_scale = float(speed) / 100 #adjust animation speed based on the character speed current_health = health current_shield = shield func adjust_health_bar() -> void: var health_bar = get_node("ProgressBar") if current_shield > 0: health_bar.get("theme_override_styles/fill").bg_color = Color(0,0,1) health_bar.get("theme_override_styles/background").bg_color = Color(0,1,0) health_bar.value = shield / current_shield * 100 else: health_bar.get("theme_override_styles/fill").bg_color = Color(0,1,0) health_bar.get("theme_override_styles/background").bg_color = Color(1,0,0) health_bar.value = health / current_health * 100 pass