Welcome to the forums @lone_dev!
A simple way to do this is have the enemy face the player when it gets within a certain distance, and then move the enemy forward. Something like this (untested):
extends KinematicBody
var player_node = null
var is_following = false
const FOLLOW_DISTANCE = 2 * 2
const MOVE_SPEED = 4
func _ready():
# we'll assume you can get the player node using something like this
player_node = get_parent().get_node("Player")
# we just need the player node so we know the position of the player in 3D space.
func _physics_process(delta):
var distance_to_player = global_transform.origin.distance_squared_to(player_node.global_transform)
if (distance_to_player <= FOLLOW_DISTANCE):
look_at(player_node.global_transform.origin, Vector3.UP)
# move the enemy (I'm assuming the enemy is a KinematicBody)
move_and_collide(global_transform.basis.z.normalized() * MOVE_SPEED * delta)
I think the code above will work, but I wrote it rather hastily, so it may have some bugs.
One thing to note with that type of solution: it will not avoid obstacles or anything, it will just try to move straight to the player regardless of what is in the way. Depending on your game though, you could use Raycast nodes (or some other method) to detect walls and then move the enemy accordingly.