Moving the enemy to the player

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By TempSchoolAcc#1

Title explains most of it. I’m trying to move the enemy to the player. For some reason, the enemy seems to start moving towards the player (floating) and then when the player starts moving, the enemy starts going up and away from the player? I have no idea what could be going wrong, as everything I’ve searched through so far seems to be roughly the same and should therefore work?

Code:

func _physics_process(delta):
    if areaExported2:
        var velocity = (areaExported2.global_position - global_position).normalized()
        move_and_collide(velocity * SPEED * delta)

func _on_EnemyDetectionRange_area_entered(area):
	if not area.is_in_group("player"):
		pass
	if area.is_in_group("player"):
		areaExported2 = area

func _on_EnemyDetectionRange_area_exited(area):
	if not area.is_in_group("player"):
		pass
	if area.is_in_group("player"):
		areaExported2 = null

Thank you for any responses, I’m completely stumped as to what it could be.

:bust_in_silhouette: Reply From: TempSchoolAcc#1

I’ve found the problem! My GUI (which I’ve been working on and off of) used to use an instanced scene of the player in the GUI scene, however, I hadn’t removed the player code, meaning that there was an invisible player running around the scene that was screwing with the path finding algorithm. After removing the player from the GUI scene, I’m just working on the GUI now, which I’ll probably do with global variables!