← Pixel Dreamer Studio

Space flying swords, shields or orbs evenly around a character for any count

Do the angle math in floats, so dividing the circle loses nothing.

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.

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

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