One Shot
Part of the Game Rules section of Coddy's Godot journey. Lesson 4 of 29.
A timer starts over every time it runs out. That suits a blinking light, but a bomb should go off only once.
Set one_shot to true and the timer runs out once, then stops:
$Timer.one_shot = trueCalling start() again sets it going for one more run.
In this castle, E opens the gate and starts a two second timer. When the timer runs out, it closes the gate.
Challenge
EasyThe timer closes the gate after two seconds, then keeps going and pushes the gate into the ground. Set $Timer.one_shot to true in _ready() so it runs out only once.
Try it yourself
extends Node2D
func _ready():
$Timer.wait_time = 2
$Timer.timeout.connect(_on_timer_timeout)
func _process(delta):
if Input.is_action_just_pressed("action"):
$Gate.position.y = 20
$Timer.start()
func _on_timer_timeout():
$Gate.position.y += 140
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Game Rules
Practice on your own: Godot playground