Random Gaps
Part of the Projects section of Coddy's Godot journey. Lesson 25 of 36.
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
EasyPut each gap at its own height.
- In
main.gd, keep each new pipe atx = 700. - Give it a random
ybetween100and250.
Press Play: the gaps come high and low. Then Check.
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)
All lessons in Projects
3Project: Flappy Flyer
Flyer GravityFlap the FlyerPractice on your own: Godot playground