How do i get the global position of nodes in my scene tree

Godot Version

4.2.2

Question

Im trying to make this “vibration system” whuch finds the position of all nodes with in a group

Im trying to use a “for loop” ( i think it is that)
Which just scanning every 1-2 frames to find the position of the node with groups like “for (group name) in the scene tree”

Im also trying to find the avarage of all of them so i can find a good spot (of course with some offset)

Sorry for no code, i dont really know how to make this without the pathfinding system
Thanks in advance

Are you confused on how to use the groups as part of a for loop?

var all_nodes := get_tree().get_nodes_in_group("MyGroup")

for node: Node3D in all_nodes:
    # do something with each node in the group
    var this_position := node.position

Im confused on how to get the avarage distance of them

A mid-point can be calculated by adding all positions and dividing by the total count. “Average distance” doesn’t make too much sense to me, if you mean to take the distance from each node to a certain point that could work, but a distance between each node to each other could get expensive fast.

To help me understand could you explain the broader problem you are trying to solve? Why are you looking for this average?

Oh sorry more like the avarage vector like
If the first noise is in 12,0,5 but the other noise maker is in 5,0,7 the agent gets the avarage of all of those if its too expensive then im trying another way

Sorry for the inconvenience

It sounds like you want a midpoint.

What is that, is it a node?

No it’s a calculation

In code it would look like this; based on the last sample

var all_nodes := get_tree().get_nodes_in_group("MyGroup")

var total_position := Vector3.ZERO
for node: Node3D in all_nodes:
    var this_position := node.position
    total_position += this_position

var midpoint := total_position / all_nodes.size()

Sorry for the late reply thanks