Welcome to the forums @ThatTatylorH1!
I would recommend placing a reference to your player either in an autoload/singleton script or using a node group to get the player. Of the two, I might suggest the latter, as it's easier to setup. Then you can use the get_nodes_in_group
function, pass the name of the group that only has the player in it, and then get the first element of the returned array to get the player. You will want to do this in the _ready
function.
Also, in the _process
function, I would suggest using the global_position
properties of both the player and the enemy for detecting which direction to move in, as position
is relative to the parent node. This means that if your player and enemy were under different parent nodes and said nodes were at different positions, comparing their position
s would lead to strange and unexpected results.