← Pixel Dreamer Studio

Make a cooking timer fire once, on time

Compare with >= and remember that it already fired, instead of checking time == 5.0.

Adding delta every frame almost never lands exactly on 5.0, so if time == 5.0 never runs. In our Godot 4.7 test it fired 0 times at 30, 60, 75, 144, 165 and 240 fps: the closest value at 60 fps was 4.999999999999988. if int(time) == 5 goes the other way and fires on every frame for a whole second, 60 times at 60 fps. Check time >= 5.0 and set a flag the first time it is true.

The code

Call start() when the food goes on the stove and tick(delta) from _process(). Connect done to your ready effect and burnt to the smoke. take_off() stops it.

extends Node
## Cooking timer that fires once when the food is done, and once when it burns.
## Call start() when the food goes on the heat and tick(delta) every frame.

signal done
signal burnt

@export var cook_time := 5.0  # seconds until done
@export var burn_time := 9.0  # seconds until burnt

var elapsed := -1.0
var _done_sent := false
var _burnt_sent := false


func start() -> void:
	elapsed = 0.0
	_done_sent = false
	_burnt_sent = false


func tick(delta: float) -> void:
	if elapsed < 0.0:
		return
	elapsed += delta
	# >= and a flag, never ==: adding up delta almost never lands exactly on 5.0
	if not _done_sent and elapsed >= cook_time:
		_done_sent = true
		done.emit()
	if not _burnt_sent and elapsed >= burn_time:
		_burnt_sent = true
		burnt.emit()


func take_off() -> void:
	elapsed = -1.0

What we measured

We added a steady delta for 10 seconds at 6 frame rates and counted how often each check ran. Two runs with the same numbers.

Why it happens

delta is a fraction like 1/60 that a float cannot hold exactly, so every addition is off by a tiny amount and the total ends up just above or just below 5.0. At most frame rates no frame lands on 5 seconds anyway. >= catches the first frame past the mark, and the flag stops it from firing again on every frame after that.

What to change

Steam that turns to smoke as it burns: steam to black smoke. Timers that should stop during pause: cooldown counting while paused. Seconds left on screen: a countdown that never shows 0 early.

Ready-made kitchen effects: Cooking & Kitchen VFX for Godot 4 has 23 presets in Stylized and Retro PSX looks, including Pot Boil, Pan Sizzle, Burnt Smoke, Pan Fire and a Fire Extinguisher.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Cooking & Kitchen VFX for Godot 4 has 23 ready-made kitchen effects for done and burnt food, including Pot Boil, Pan Sizzle, Burnt Smoke and Pan Fire, in Stylized and Retro PSX looks.

More how-tos for Cooking & Kitchen VFX for Godot 4: Steam that turns to black smoke when the food burns · A countdown that never shows 0 while time is left

More how-tos: Game systems