I'm new to godot and currently working on a little game where there's a lot of objects which are supposed to be pointing at some specific points on the game map, and I'm trying to do that with look_at() but having some trouble with it :disappointed:

This is the code I was initially using (the rotation correction here always doing a deg2rad calculation is supposed to be only temporary, it's pretty unoptimized to do this way lol)

And this is the result It's supposed to be pointing completely towards that red godot icon, removing the correction also doesn't help as it's supposed to be facing something like upside down to the right, it doesn't do that here.

BUT I tried out a little makeshift solution by doing the angle calculation by myself

And it works perfectly this way or almost perfectly lol

also, when I try calling global_position for a parented node it gives me some craaaazy numbers, having nothing to do with it's actual position I guess

and this is my current workaround which gives me the correct position, PMPosition being the node for the little red godot sprite

Can someone explain what is happening here?

Godot works in local coordinates. Though you can use global, you have to be consistent. I think in your case, it would be easier to transform the point you are looking at into local coordinates first before using look at.

like this?

if so, it's still giving me issues :confused:

No, I mean for the original destination / look_at calculation.

So, I went back with the original position code to give the coordinates that were originally fed to the look_at function

Like this

And did the local coordinates transform

Results are still undesirable :confounded:

Well, I think you want to use xform, not xform_inv. Also, why are you adding 90 degrees? You should adjust the original object so it is the right orientation.

Node2D.look_at() expects the position argument to be in global space.

@cybereality said: Well, I think you want to use xform, not xform_inv. Also, why are you adding 90 degrees? You should adjust the original object so it is the right orientation.

Did exactly that

Still looking at the wrong direction :cry: (it remains this way no matter where I place it on the map)

Is it always off by like 90 degrees? If I recall correctly, the look_at function rotates the node so that the X axis is pointing towards the target. This means you may need to add an offset after calling look_at if your sprite faces in another direction:

look_at($target.global_position)
rotation += deg2rad(90)

I would try to avoid transforming the position if you can and just pass the global position directly to the function if at all possible. If you need to convert the position, I believe you can use the to_local and to_global functions:

look_at(to_global(destination))
rotation += deg2rad(90)
10 months later