A ring of flying swords usually places sword i at 360 / count * i degrees. In GDScript 360 and count are both whole numbers, so the division drops the remainder. In our Godot 4.7 test 3, 4, 5, 6, 8, 9, 10 and 12 swords looked fine, but 7 swords got gaps of 51 degrees and one of 54, and 11 swords gaps of 32 and one of 40. TAU * i / count in radians spaced every count evenly.
The code
Add the script to a Node3D on your character and put the swords, shields or orbs under it as children. It spaces and spins however many there are, so adding or removing one just works. Set radius and degrees_per_second.
extends Node3D
## Places every child (flying swords, shields, orbs) evenly on a ring around this
## node and spins them, for any number of children.
@export var radius := 1.5
@export var degrees_per_second := 90.0
var _angle := 0.0
func _process(delta: float) -> void:
_angle = wrapf(_angle + deg_to_rad(degrees_per_second) * delta, -PI, PI)
var items := get_children()
var n := items.size()
for i in n:
var a := _angle + TAU * i / n # float math, so nothing is lost to rounding
(items[i] as Node3D).position = Vector3(cos(a), 0.0, sin(a)) * radius
What we measured
3 to 12 objects, the biggest and smallest gap between neighbours around the ring. Two runs with the same numbers.
deg_to_rad(360 / count * i): even for 3, 4, 5, 6, 8, 9, 10 and 12. 7: gaps 51 to 54 degrees. 11: gaps 32 to 40 degrees.- The script, with real child nodes: 51.4 degrees every gap for 7, 32.7 for 11, and even for all the others.
Why it happens
360 / 7 in whole numbers is 51, not 51.43. Six steps of 51 end at 306 degrees, so the last gap back to 0 is 54. Counts that divide 360 exactly hide the bug until a player gets the 7th sword. Writing 360.0, or using TAU, keeps the remainder.
What to change
- A half ring behind the player: use PI instead of TAU and start at the angle behind them.
- To tilt the ring, rotate the Node3D that holds the children.
Qi drawn in from all around: charge-up particles. Keep a spinning thing at the same speed: wrap the angle.
Cultivation effects: Xianxia VFX has Qi Absorption and Golden Core Formation: streams of qi drawn in from all around and compressed into a golden core, ready for Godot 4.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Xianxia VFX has Qi Absorption and Golden Core Formation: streams of qi drawn in from all around and compressed into a golden core, ready for Godot 4.
More how-tos for Xianxia VFX: Point swords, projectiles and models that face +Z at the target
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
- Spin a magic circle forever at the same speed
- Text around a circle with even gaps