Multiple nodes rotating around another node or point.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By 9BitStrider
offset += 2 * PI * delta / float(rotation_duration)
offset = wrapf(offset, -PI, PI)

var new_pos = Vector2()

new_pos.x = cos(offset) * radius.x
new_pos.y = sin(offset) * radius.y
position = global_position + new_pos

The above code works for one node. How to I spread it evenly between multiple nodes orbiting a single object or point in my game? Trying to make a ring menu like in Secret of Mana.

I managed to get it working how I want. Now the problem is stopping the icons at a certain angle. Here is the code I’m using:

var rotate = true
var rot_dir = 1
var radius
var rotate_dur = 1.0
var dist = Vector2(60, 10)
var chars = []
var orbit_ang_offset = 0

func process(delta):
    if rotate:
		radius = Vector2.ONE * dist
		
		orbit_ang_offset += (2 * rot_dir) * PI * delta / float(rotate_dur)
		orbit_ang_offset = wrapf(orbit_ang_offset, -PI, PI)
		
		if chars.size() != 0:
			for i in chars.size():
				var spacing = 2 * PI / float(chars.size())
				var new_position = Vector2()
				new_position.x = cos(spacing * i + orbit_ang_offset) * radius.x
				new_position.y = sin(spacing * i + orbit_ang_offset) * radius.y
				chars[i].position = new_position

What I want them the icons to do is stop at the bottom of the orbit, meaning the icon is highlighted and ready for selection. How would I do this?

9BitStrider | 2021-04-09 18:16