← Pixel Dreamer Studio

A slot reel that always lands forward on the result

Pick the next spot ahead where the result sits in the middle, then ease into it at the speed the reel is already spinning.

Keep the reel's offset counting up in symbols and stop it at forward_target(): the next offset ahead of the reel with the result in the middle, plus a full turn. Tween to it with TRANS_CUBIC and EASE_OUT for 3 times the distance divided by the spin speed, in seconds, so it does not lurch. In our Godot 4.7 test on a 12-symbol reel, tweening to the result in the same lap ran the reel backwards in 523 of 1,000 stops, and stopping as soon as the result's cell came into the window left 962 of 1,000 stops off centre at 60 fps and showed the wrong symbol in 269 at 30 fps. The script below landed dead centre on the right symbol in all 1,000 and never moved backwards.

The code

Save it as reel_stop.gd and load it with const ReelStop := preload("res://reel_stop.gd"). Keep one number per reel, offset, counted in symbols, that only goes up while it spins, and draw the strip from fposmod(offset, 12). When the result is decided, tween offset to ReelStop.forward_target(offset, result, 12) for ReelStop.landing_time(offset, target, spin_speed) seconds. shown_symbol() reads the symbol in the middle by rounding, not cutting off.

extends RefCounted
## Stop a looping slot reel on a chosen symbol, always moving forward.
## offset is counted in symbols: 0.0 = symbol 0 in the middle of the window, 1.0 = symbol 1, and so on.
## It only grows while the reel spins, so draw the strip with fposmod(offset, strip_size).
##   var target := ReelStop.forward_target(offset, result, 12)
##   var seconds := ReelStop.landing_time(offset, target, spin_speed)
##   create_tween().tween_property(self, "offset", target, seconds) \
##       .set_trans(Tween.TRANS_CUBIC).set_ease(Tween.EASE_OUT)
##   # when it ends: ReelStop.shown_symbol(offset, 12) == result


## The offset to tween to: ahead of offset, with symbol in the middle, after extra_spins full turns.
static func forward_target(offset: float, symbol: int, strip_size: int, extra_spins := 1) -> float:
	var ahead := fposmod(float(symbol) - offset, float(strip_size))
	return roundf(offset + ahead) + extra_spins * strip_size


## Tween time that starts the landing at the speed the reel is already spinning (symbols per second).
## TRANS_CUBIC + EASE_OUT starts at 3 x distance / time, so a fixed time jumps faster or slower.
static func landing_time(offset: float, target: float, spin_speed: float) -> float:
	return 3.0 * (target - offset) / maxf(spin_speed, 0.001)


## The symbol in the middle of the window.
static func shown_symbol(offset: float, strip_size: int) -> int:
	return posmod(roundi(offset), strip_size)

What we measured

A reel strip of 12 symbols spinning at 20 symbols a second. We stopped it 1,000 times from random positions on random results, with the same seed for every method, and read the middle symbol by rounding. The easing came from Tween.interpolate_value(), the same curve create_tween() uses, sampled at 30, 60 and 144 frames a second, and we ran one real tween on a property as well.

Why it happens

A looping strip shows the same symbol every 12 steps, so the result can be reached at many offsets. The one in the current lap is behind the reel about half the time, and a tween goes straight to its end value, so it scrolls backwards to get there. Stopping when the result's cell first reaches the window stops wherever the last frame left the reel, and int() cuts that fraction off while the picture shows the nearest symbol. fposmod(result - offset, 12) is how far ahead the result is, always from 0 up to 12, so adding it to the offset only moves forward and lands on a whole symbol. An ease-out cubic starts at three times its average speed, so the time that keeps the spin speed is 3 times the distance divided by the speed.

What to change

Ready-made reels: Slot Roguelike Kit for Godot 4 has a reel that lands on the symbols you give it with stop_on(), always scrolling forward, easing in from its spinning speed and bouncing when it lands, with extra symbols passing first and a slower landing for the anticipation on the last reel.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Slot Roguelike Kit for Godot 4 has reels that land on the symbols you choose with stop_on(), always scrolling forward and easing in from the spin speed, with a bounce and a slower last reel for anticipation.

More how-tos: Game systems