Start a Timer
Part of the Game Rules section of Coddy's Godot journey. Lesson 2 of 29.
The lighthouse timer started by itself because its autostart was on. Often a timer should wait, like a cooldown that starts when you attack.
This castle's Timer has autostart off. Call start() to set it going:
$Timer.start()It then sends timeout every second. Calling start() again starts the count over.
The script already raises the gate 35 pixels on every timeout.
Challenge
EasyStart the gate's timer when the player presses E (the action input). In _process(), call $Timer.start() when action was just pressed.
Try it yourself
extends Node2D
func _ready():
$Timer.timeout.connect(_on_timer_timeout)
func _process(delta):
pass
func _on_timer_timeout():
$Gate.position.y -= 35
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