+1 vote

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


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


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))


I'm using 3.0 stable.

in Engine by (16 points)

2 Answers

+3 votes
Best answer

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.

by (29,090 points)
selected by

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

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^^

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.

+4 votes

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).

by (22 points)

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)
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.