Look_at is not rotating the node to the correct position or is my scene backwards

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Deith

The issue I’m having is that when I use look_at(player.global_transform.origin, Vector3.UP) on the NPC I’m trying to rotate towards player the result is that the NPC is rotating, but it’s not rotating to look exactly at the player, it’s like it’s 90 degrees off. Like this And after looking up documentation and tutorial it seems that maybe it’s my scene and meshes are wrong. Both player and NPC have all transform.rotations set to 0 on y. In the viewport they look to the right (the nose is a child node of the body mesh instance)
player viewport: https://imgur.com/B6cBzCR
ncp viewport: https://imgur.com/ZjMXO8G

And I’m calling look_at on the whole NPC scene, not just mesh instance.

So what am I doing wrong? Cause everywhere look_at seems to just work in 3D, but for me it doesn’t work at all.

So I rotated just the mesh, not spatial parent node of NPC by 90 degrees on Y and now it works - like this https://imgur.com/SDxh3WF but I still don’t understand why I had to and why it worked. It will be kinda awkward to have the mesh look away in the NPC scene when the model is replaced.

Deith | 2022-10-13 15:32

:bust_in_silhouette: Reply From: Wakatta

By default all Spacial’s forward axis are considered to be -Z the one facing away from the camera by default.

Not sure why the devs have done this because every other 3D software uses+Z the one facing the camera by default.

All of that is a trivial matter that you will eventually get accustomed to (or forever hate).

If you designate your facing direction to be anything other than -Z then look_at will need the offset from that direction.


#so for your first image
look_at(player.global_transform.origin + Vector3.RIGHT, Vector3.UP)