← Pixel Dreamer Studio

Make the fish bite after the same wait at any frame rate

Roll the wait once when the bobber lands, in seconds, instead of rolling a chance every frame.

A chance rolled in _process() is rolled once per frame, so a faster screen rolls it more often. In our Godot 4.7 test randf() < 0.01 every frame made the fish bite after 3.32 seconds on average at 30 fps, 1.68 s at 60, 0.71 s at 144 and 0.42 s at 240. Roll the wait once when the line lands, then count it down with delta.

The code

Call cast() when the bobber lands in the water. Then call bite_due(delta) every frame and start your bite effect and the reel-in window on the frame it returns true. Call reel_in() if the player pulls the line out early.

extends Node
## Fishing bite wait that is the same at any frame rate.
## Call cast() when the bobber lands, then bite_due(delta) every frame:
## it returns true once, on the frame the fish bites.

@export var average_wait := 6.0  # seconds, on average
@export var min_wait := 1.5  # no fish bites sooner than this

var _left := -1.0


func cast() -> void:
	# Roll the wait once, in seconds. It still feels like "could bite any moment",
	# but the frame rate cannot change it.
	var r := maxf(1.0 - randf(), 0.000001)
	_left = min_wait - log(r) * maxf(average_wait - min_wait, 0.01)


func bite_due(delta: float) -> bool:
	if _left < 0.0:
		return false
	_left -= delta
	if _left > 0.0:
		return false
	_left = -1.0
	return true


func reel_in() -> void:
	_left = -1.0  # call when the player pulls the line out early

What we measured

We simulated 2,000 casts for each way at a steady 30, 60, 144 and 240 frames per second. Same random seed, two runs with the same numbers.

Why it happens

A 1% chance per frame is 1% every 1/30 of a second at 30 fps and 1% every 1/240 of a second at 240 fps: eight times as many rolls in the same time. Multiplying the chance by delta fixes the average, but a chance that can hit on any frame always lets some fish bite the moment the bobber lands. The script rolls the same kind of random wait once, as a number of seconds, starts it after the minimum, and counts it down by delta, so a slow frame or a fast screen only changes how finely it is counted.

What to change

The rings around the bobber: water ripple rings lying flat on the surface. Chances that fail too many times in a row: pseudo-random chance.

Ready-made fishing effects: Fishing VFX for Godot 4 has 25 presets in Stylized and Retro PSX looks, including nibble and bite effects, bobber ripples and splashes, fish shadows and a rare catch rainbow.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Fishing VFX for Godot 4 has nibble and bite effects, bobber ripples and splashes, fish shadows and a rare catch rainbow, in Stylized and Retro PSX looks.

More how-tos for Fishing VFX for Godot 4: Ripple rings around a fishing bobber

More how-tos: Game systems