Strange Behavior With look_at

Godot Version

4.2.2

Question

Hello! I recently started using Godot after using Unity for several years. I’ve started a simple first person project to test some things out, but I keep encountering really strange behavior with the look_at function.

I’ve combed through a bunch of threads and tutorials for the last several hours, but am completely stuck as to why this function won’t work like how I expect.

For example, I created a very simple object called the ‘looker’, which is meant to act like a turret that looks at the player:


This object has a very simple script that should just make it track the player:

func _process(delta):
	var player = get_node("/root/Node3D/Player/player_body")
    look_at(player.position)

In game, it takes on a totally wrong rotation:
image
I’ve tried messing around with the second parameter for look_at, changing the rotation of the object in the scene, changing the rotation edit mode, and more. Some of these tweaks do change how the object rotates, but nothing seems to actually make this work as I would expect. I feel like I must be missing something.

Try look_at(player.global_position,Vector3.UP)

1 Like

I copy the answer to your reddit post here as well :wink:

var look_dir = player.global_position
# Avoid looking up/down
look_dir.y = 0
look_at(global_position + look_dir, Vector3.UP)
1 Like

That worked, thanks! I didn’t realize position and global_position were distinct.