Problem with look_at()

Hi I am trying to use a look_at() function in order for the enemy to look at the player, but it’s not working, am getting the error “Invalid get index ‘global_transform’ (on base: ‘null instance’)” . What am I doing wrong?

@onready var target = $Player
look_at(target.global_transform.origin ,Vector3(0,1,0))

Please provide more information, like when is look_at called? Is the path actually correct? Is Player a child of this script?

1 Like

player isn’t the child of the script.

Then you can’t reach it because $Player means “the child of this node named Player”

You can drag in the node from the editor and press ctrl before you let go of ito make an onready var that has the correct path.