Menu
CoddyTech

Pipes on a Timer

Part of the Projects section of Coddy's Godot journey. Lesson 21 of 33.

Next come the pipes. A pipe is a scene, pipe.tscn: a top half and a bottom half with a gap between them. In pipe.gd it slides left at SPEED pixels per second. Past the left edge it removes itself, so old pipes do not pile up:

position.x -= SPEED * delta
if position.x < -60:
	queue_free()

The scene has a Timer called PipeTimer that fires every 1.6 seconds. In main.gd, connect its timeout signal and make a pipe past the right edge:

func _on_pipe_timer_timeout():
	var pipe = PIPE.instantiate()
	pipe.position = Vector2(700, 180)
	$Pipes.add_child(pipe)

Godot draws nodes in tree order. Pipes comes before Ground, so the ground covers the bottom of every pipe.

challenge icon

Challenge

Medium
  1. In pipe.gd, add const SPEED = 160. Move the pipe left every physics frame and remove it once position.x is under -60.
  2. In main.gd, add const PIPE = preload("res://pipe.tscn") and connect $PipeTimer.timeout. On every timeout, make a pipe at (700, 180) in the Pipes node.

Try it yourself

extends Node2D

func _ready():
	pass
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Projects

Practice on your own: Godot playground