CHALLENGE 2: Horizontal Movement With get_axis() ==================================================================== TASK ---- Create move_left/move_right actions and write a script using Input.get_axis() that moves a Sprite2D horizontally at 250 pixels per second in whichever direction is held, with no movement when neither is pressed. SETUP ----- 1. Project > Project Settings > Input Map. 2. Add a "move_left" action, bind it to the left arrow (or A). 3. Add a "move_right" action, bind it to the right arrow (or D). SOLUTION CODE (attached to the Sprite2D) -------------------------------------------- extends Sprite2D const SPEED = 250.0 func _physics_process(delta: float) -> void: var horizontal := Input.get_axis("move_left", "move_right") position.x += horizontal * SPEED * delta WHY THIS WORKS AS AN ANSWER ---------------------------- Input.get_axis("move_left", "move_right") returns a single float: -1.0 while move_left is held, 1.0 while move_right is held, and 0.0 whenever neither (or both, cancelling out) is pressed. Multiplying that value by SPEED * delta gives the exact frame-rate-independent movement amount to add to position.x this frame - when the result is 0.0, position.x doesn't change at all, satisfying the "no movement when neither is pressed" part of the task automatically, with no separate if/else needed to handle that case. This is the same delta-scaled movement pattern used since Chapter 1 and Chapter 4 - the only new part here is that the direction (1, -1, or 0) now comes from real keyboard input each frame instead of being a fixed constant.