The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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( + "/target")
        var local_trans = enemy.get_global_transform().origin

        var pos = target.get_translation()
        var camera = get_tree().get_root().get_camera()
        var screen_pos = camera.unproject_position(pos)


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)
in Engine by (21 points)

what kind of node is the "target"? why are you translating it?
Could it be the target has shared properties among all the enemies (like a mesh) and when you translate it on the first enemy it does it on the remaining ones as well?
try unprojecting the enemy position directly instead of the target and see what happens

"The target" is one target per enemy. Before this code there's another for loop that generates a Spatial (the one I mentioned for the vector conversion, AKA "target") when the player enters an area. Each target is a child of its enemy.

I just tried the enemy's position directly and it made disappear each of them... And a few seconds later it froze MY COMPUTER. Had to do a hard reset.

lol, sorry!
share the project so we can have a look

At this point I don't mind, so give it a try. If some comments on scripts look weird or very ambiguous, they're just placeholders.

Please read the README file so you can learn what I'm trying to achieve.

Dont know if this is what you were looking for, but as i wrote before i made the unprojection directly on the enemy position, modifying your

var screen_pos = camera.unproject_position(pos)


var screen_pos = camera.unproject_position(enemy.global_transform.origin)

Now when i select "Attack=>normal" some red arrows appear at the bottom of the enemy position.
I guess you wanted to use target to control the position of the arrow: if that's true you found a pretty convoluted way to do it, i would simply have done a

var arrow_offset=Vector3(x,y,z)

Ummm yup!!!! This is what I was trying to do! Thank you so much!

By the way, this still doesn't answers my original question, so I don't know what to do with this page, lol.

1 Answer

+1 vote
Best answer

By the way, i double checked the code, the error is in the


because translate(x) does not place the object into x, but move the object by x. And since you were calling it every frame, every frame was going to move the targe a bit, exiting the viewport after a couple frames.
You should use

by (1,514 points)
selected by

Okay once again thank you so much. I still kind of wanted the spatial node because I realized I could use it to point at specific elements. I'll use both this answer and your other comment in my code.

Btw I'll just delete my project from Dropbox now.


Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.