I'm getting the wrong camera (object?). It gets the active camera only once, and then it goes for something else.
onready var everyone = get_children()
var coordinates = [] setget list_update
func list_update(haha):
coordinates = haha
func _process(delta):
var new_coordinates = []
for enemy in everyone:
var target = get_node(enemy.name + "/target")
var local_trans = enemy.get_global_transform().origin
target.translate(get_transform().basis.xform(local_trans))
var pos = target.get_translation()
var camera = get_tree().get_root().get_camera()
var screen_pos = camera.unproject_position(pos)
new_coordinates.append(screen_pos)
list_update(new_coordinates)
Basically this converts Vector3 from Spatials into Vector2 based on the camera. I append the values to an array because I want another script to use them.
Printing the first index is how I discovered this issue:
(284.538025, 465.474213)
(643.855469, 1740.325562)
(642.883728, 1736.87793)
(642.561035, 1735.732788)
(642.399902, 1735.161133)