there is the code, i used daniel buckley tutorial,
func _physics_process(delta):
if is_on_floor():
gravity = 0
else:
gravity = -0.98
if Input.is_action_pressed("shift"):
moveSpeed = 16
if Input.is_action_just_released("shift"):
moveSpeed = 10
if translation.distance_to(player.translation) <= attackRange and alerta<10:
var dir = (player.translation - translation).normalized()
dir.y = gravity
move_and_slide(dir * moveSpeed, Vector3.UP)
if alerta >= 10:
var dir = (player.translation - translation).normalized()
dir.y = gravity
move_and_slide(dir * moveSpeed, Vector3.UP)
Shift is to increase speed when player is running, and alerta is for when he gets shoot no matter the distance to player, he starts chasing him. I tryed to add the if is_on_floor
but as i said it keeps moving rarely and gets stuck.