Node2D keeps rotation exactly as you set it, so rotation += speed * delta grows forever, and a big number cannot take small steps exactly. In our Godot 4.7 test at 60 degrees a second, with rotation set to where it would be after 1 hour, each frame's step was 0.01733 instead of 0.01745 radians. After 10 hours 0.01563, 10% slow. After 100 hours 0.03125, nearly twice as fast. Wrapping the angle between -PI and PI kept every step at 0.01745.
The code
Put the script on the Node2D or Sprite2D that spins, and set degrees_per_second. Use a negative value to spin the other way.
extends Node2D
## Spins forever (magic circles, loading rings, portals) at the same speed, even
## after hours, by keeping the angle between -PI and PI.
@export var degrees_per_second := 60.0
func _process(delta: float) -> void:
rotation = wrapf(rotation + deg_to_rad(degrees_per_second) * delta, -PI, PI)
What we measured
A Node2D at 60 degrees a second, 0.01745 radians a frame at 60 fps. Rotation set to the angle it reaches after 0, 1, 10 and 100 hours, then 60 frames of +=. Two runs with the same numbers.
- A Node2D set to 123456.789 read back 123456.789: it does not wrap the angle by itself.
- += from 0: 0.01745 a frame. From 3,770 rad (1 hour): 0.01733. From 37,699 rad (10 hours): 0.01563. From 376,991 rad (100 hours): 0.03125.
- The script, one hour of frames: the angle stayed between -3.1416 and 3.1241, every step 0.01745 to 0.01746.
Why it happens
The angle is stored with limited precision, and the bigger it is, the coarser the steps it can hold. At 37,699 radians the nearest step it can store to 0.01745 is 0.01563, so every frame adds that instead. Keeping the angle between -PI and PI keeps it small, where steps are exact. The sprite looks the same, since a full turn is a full turn.
What to change
- The same goes for anything that only grows: a timer fed to a shader, a scroll offset, a bobbing phase. Wrap it after one full cycle.
The shader version of this: scrolling texture jumps once an hour. Spinning circles that look grainy when small: mipmaps for magic circles.
Magic circles to spin: PD Sigil Forge Pro generates magic circles in 8 styles and exports large PNGs, SVG and spinning animations.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: PD Sigil Forge Pro generates magic circles in 8 styles and exports large PNGs, SVG and spinning animations.
More how-tos: Auras, rings, beams and weather
- Light shaft cards without the bright edge-on line
- Stretch a bolt sprite from the caster to the target
- Space lights, posts or coins evenly along a Path3D
- Stop a big spinning texture from looking grainy when it is drawn small
- God rays without volumetric fog
- Dark horror fog that works in Compatibility
- Magic aura particles that circle a character
- Charge-up particles that fly in to the middle
- Particle ring standing up instead of flat
- 2D particles from a sprite's shape
- A glowing circle on the ground
- A loot beam that never goes flat
- Chain lightning between enemies
- A tower's attack range ring
- Enemy vision cone with a "!" when it spots you
- Rain that follows the camera
- Rain falling through the roof
- Snow particles not falling
- orbit_velocity not working in 3D: use tangential_accel
- Rain falls through the player
- Snow that stays on roofs
- Emit particles along a Path3D
- Ambient particles in many places from one emitter
- Keep a buff aura on until the last buff really runs out
- Space flying swords, shields or orbs evenly around a character for any count
- Text around a circle with even gaps