Look_at looks exactly at the opposite direction

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

I created an Enemy, put a cube in his front so I could be sure of the direction he’s facing:

enemy

Then I created an scene with a dot that represents the destination of the enemy (EndPoint):

tree

Then I’m running this code to make the Enemy face the EndPoint, but it looks at the opposite direction:

func _process(delta):
	var endposition = get_parent().get_node("EndPoint").global_transform.origin;
	look_at(Vector3(endposition.x, translation.y, endposition.z), Vector3(0, 1, 0))

play

I’m using 3.0 stable.

:bust_in_silhouette: Reply From: Zylann

Keep in mind Godot uses OpenGL convention for its transforms, so looking forward means looking at the negative Z axis.
You can verify this if you create a Camera node and use look_at on it: you will see the Z axis will be exactly backwards, but the camera will look in the right direction.
The fix for your cube is to design it in the other direction.

Thanks for the the answer!
So, if I design the cube in the other direction and see the “Front View” in the scene, I should actually see it’s back?!

This is my current Front View, facing towards Z positive:

enter image description here

And this is Right View:

enter image description here

aaforcebox | 2018-02-01 20:30

Yes, looking “forwards” means positionning the view such ass the Z axis is pointing towards you. But I have to admit the view names are confusing^^

Zylann | 2018-02-01 20:43

Right. Godot devs should make the Front view look from the other side, once currently it’s actually looking the back of everything. Also, the forward=negativeZ is something that devs from other engines might not know… Maybe it could be shown in the starting tutorials and docs.

aaforcebox | 2018-02-01 20:56

Heheh https://twitter.com/DJ_Link/status/952185276218200065
Godot would be top-right

Zylann | 2018-02-01 21:01

:bust_in_silhouette: Reply From: trotter

Alternatively you can rotate your object the other way once you rotated it toward the player:

	look_at(cible.global_transform.origin, Vector3(0, 1, 0))
	self.rotate_object_local(Vector3(0,1,0), 3.14)

3.14 radian works in my case, try between 0 and 6.2 (depend how you imported you object I guess).

3.14 is part of the number PI (3.1415926…)
Radian is an other way to describe an angle and 2 * PI equals 360°
Which means half of it … just PI … equals 180°
So you are rotating the object about 180° which makes sense since you want it to look in the “other direction”. (It doesn’t depend on how the object got imported)

So in your example you could use this (also added Vector UP):

self.rotate_object_local(Vector3.UP, PI)

Hunter99 | 2021-08-30 21:52