Hi, I recently started making a 3D game, and have created a goblin enemy that follows the player. I wanted it to look at the player when running at it, so I added the look_at function.
Code for looking (inside _physics_process(delta)):
look_at(player.global_transform.origin, Vector3.UP)
move_and_slide(direction.normalized() * speed, Vector3.UP)

The problem I have is that when the player jumps or the enemy gets very close to the player, the whole enemy tilts up, which looks very bad. Is there a way that the enemy can look at the player ONLY on the x and z axis, and not the y? Or is there just a better way to rotate the enemy towards the player?

Any replies would be really really appreciated- I'm pretty out of my depth here lol.

There is a way to do this.

self.global_transform.rotation_degrees.x=0
self.global_transform.rotation_degrees.z=0
This works in godot 3.4
In godot 4.0 you must use different functions.

Because the y axis is up and down, you only want the y rotation. And not z or x.

Oh that might be without global_transform

    newmodels Thank you so much! And yes it was without the global_transform bit, but either way thank you so much for the help 🙂