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.
- Tween to the result in the same lap,
offset - fposmod(offset, 12) + result, for 1.2 s: the right symbol every time, but the reel ran backwards in 523 of 1,000 stops, up to almost a full turn, and the stops that went forward spun 10.5 symbols at most, less than one turn. - Keep spinning and stop as soon as
int(offset)is the result: the result's cell had only just arrived, so 962 of 1,000 stops at 60 fps were off centre, by 0.17 of a symbol on average. Reading the middle by rounding then showed the next symbol in 44 stops at 60 and at 144 fps, and in 269 at 30 fps, where the reel moves two thirds of a symbol each frame. When the result was already in the window it stopped on the spot, up to half way between two symbols. forward_target()with a fixed 1.2 s tween: centred on the right symbol in all 1,000 and never backwards, but the first frame of the landing ran at 30 to 59 symbols a second, up to three times the spin speed, so the reel jumps forward as it starts to stop.forward_target()withlanding_time(): centred on the right symbol in all 1,000 at 30, 60 and 144 fps, never backwards, 12 to 24 symbols of travel, and the first frame ran at 19.6 to 20 symbols a second, the speed it was spinning at.- A real
create_tween()from offset 37.4 to the result 5: target 53, 2.34 seconds, ended at exactly 53.0 with symbol 5 in the middle and no frame going backwards.
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
- More drama: pass a bigger
extra_spins. Withlanding_time()a reel with further to go also takes longer, so the reels you give more extra spins land later. - Decide the result first, with the machine's own generator, then stop on it: same seed, same results.
- Once the reels stop, pay what the player sees: wild symbols at the start of a line.
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
- Hover a 3D object inside a SubViewport
- A turned building that covers the cells it stands on
- An inventory that never loses an item and never overfills a stack
- A JSON save that loads back exactly what you saved
- Fire that spreads one cell per step, in every direction
- A pooled enemy that comes back as fresh as a new one
- An enemy that stops at the dead player and finds the respawned one
- Poison, burn and bleed that keep ticking when applied again
- XP, qi and gold that keep growing without going negative
- Count slot line wins with wilds in front
- Random directions spread evenly over a sphere or a cone
- Count a lap only when the car really went round
- Make a seed repeat: daily runs, replays and roguelike seeds
- Offline progress that counts the time the game was closed
- A chance roll without the long bad-luck streaks
- Check crafting recipes in any order, with the right counts
- Make HP and mana regen the same at any frame rate
- Damage over time with the right number of ticks
- Spawn enemies where the camera cannot see them
- Keep a chasing horde from stacking into one enemy
- Make the fish bite after the same wait at any frame rate
- Snap buildings to the right grid cell on both sides of the origin
- Make a cooking timer fire once, on time
- Pick from a weighted loot table with the right chances
- Level up as many times as the XP covers
- Walk a patrol guard to each point without overshooting
- Remove items from an Array while checking them, without skipping any
- Scatter spikes, roots or trees in a circle without overlaps
- Count and take crafting items from every stack
- Play random sounds and events without obvious repeats
- Pick the growth image so the ripe one shows exactly when the crop can be picked
- Turn a day counter into season, day and year without a day 0
- An enemy that dies once, however many hits land
- A fair shuffle you can replay
- A ghost that drives the lap at real speed
- A vision cone that does not flicker at the edge
- Move a group of units without a pile-up
- A sprinkler that waters a round patch
- A crowd of NPCs that never emote or bob in step
- A song position that moves on every frame
- Nodes your editor tool adds that stay in the scene