Random Gaps
Part of the Projects section of Coddy's Godot journey. Lesson 22 of 33.
Every gap is at the same height, so you could stay at one height and never crash. Put each gap somewhere new. A pipe's position.y is the middle of its gap:
pipe.position = Vector2(700, randf_range(100, 250))From 100 to 250, the gap is never too close to the top or the ground, so every pipe can be passed.
Challenge
EasyIn main.gd, put each new pipe at x = 700 and a random y between 100 and 250.
Try it yourself
extends Node2D
const PIPE = preload("res://pipe.tscn")
func _ready():
$PipeTimer.timeout.connect(_on_pipe_timer_timeout)
func _on_pipe_timer_timeout():
var pipe = PIPE.instantiate()
pipe.position = Vector2(700, 180)
$Pipes.add_child(pipe)
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