0 votes

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.

Godot version 3.5.1.stable
in Engine by (62 points)

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.

1 Answer

+1 vote
Best answer

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.

Example

#so for your first image
look_at(player.global_transform.origin + Vector3.RIGHT, Vector3.UP) 
by (6,264 points)
selected by
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.