CHALLENGE 1: A Patrolling Hazard ==================================================================== TASK ---- Add a second Hazard that patrols back and forth between two points using _physics_process and position (Chapter 4's own movement pattern), rather than sitting still. It should still damage the player on contact exactly like the first Hazard. SOLUTION CODE (attached to the second Hazard's Area2D root) ------------------------------------------------------------------ extends Area2D @export var patrol_distance: float = 150.0 @export var patrol_speed: float = 60.0 var start_x: float var direction: int = 1 func _ready() -> void: start_x = position.x body_entered.connect(_on_body_entered) func _physics_process(delta: float) -> void: position.x += direction * patrol_speed * delta if position.x > start_x + patrol_distance: direction = -1 elif position.x < start_x - patrol_distance: direction = 1 func _on_body_entered(body: Node2D) -> void: if body.is_in_group("player"): body.get_node("Health").take_damage(20) WHY THIS WORKS AS AN ANSWER ---------------------------- The damage-on-contact half is completely unchanged from the capstone's own hazard.gd - body_entered is still connected the same way, and _on_body_entered still checks the "player" group and calls take_damage(20) exactly as before. Patrolling and damaging are two independent responsibilities that don't interfere with each other. The patrol logic reuses Chapter 4's own delta-scaled movement pattern (position.x += direction * patrol_speed * delta), just with a direction that flips between 1 and -1 instead of staying constant. start_x records the hazard's own starting X position once, in _ready() - every frame after that, the hazard's current position.x is compared against start_x + patrol_distance and start_x - patrol_distance, flipping direction the moment either boundary is crossed. Because this Hazard is still an Area2D (not a CharacterBody2D), it moves by directly changing position rather than using move_and_slide() - which is fine here, since a patrolling hazard isn't expected to be blocked by walls the way the player is.