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.