look_at(target, Vector3(0,1,0)) rotates around more than just y-axis?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By cgardner
:warning: Old Version Published before Godot 3 was released.

Hello!

I’m trying to script a simple guard for a 3rd-person game, and I would like the guard to turn to face the player when entering his FOV (a collision box).

However, this code:

look_at(playerref.get_transform().origin, Vector3(0,1,0))

does this:
does this.

The small character is the player, the large one is a guard (same model, placeholder assets so the scales are goofed up).

Why is the guard model rotating in x-axis as well as y-axis?
I thought that look_at() was supposed to rotate around the “up” axis given as input? Is there a way to use look_at() while only rotating around y axis? Also, what is the “forward” direction for a character? You can see the model on the right is facing away, is -z the “forward” direction?

FWIW I’ve read through this article on motion and rotation, but it seems to just say “use look_at().”

Thank you for your help!!!

:bust_in_silhouette: Reply From: wombatstampede

The Vector3 just says where “up” is for look-at. To be more specific: If you used Vector3(0,-1,0) then your guard would still look in the same direction but with feet up and head down.

You could tell look_at to a look at a position which is composed of the x and z coords of the object and the y coord of the “viewer”.

“Forward” depends a bit on how you edit your models. But I also use -z as forward and +x as right.

I also did a post about 3D Vectors + Physics in the forum. Not specifidally about look_at but that’s a good idea for a topic to add.
https://godotdevelopers.org/forum/discussion/18480/godot-3d-vector-physics-chea

Thank you for the help! I appreciate it!!

cgardner | 2017-07-05 18:36