0 votes

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.

in Engine by (15 points)

2 Answers

+2 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 (27,664 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.

+1 vote

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 (16 points)
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 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 webmaster@godotengine.org with your username.