The enemy can "see" the player or "hear" when the player is near. Then pursuit and shoot when the player is on sight. If the player it out of sight and far from the hear area, it goes back to an idle state.
Viewing post in 8 directional Sprite + FPS Controller Godot comments
In my Tanks! Template I improved the enemy AI. It has a patrol state going to random areas instead of an idle state. If the player is on sight it shoots. If the player is near enough but not in sight, then it goes in a pursuit mission. But if the player goes away too far, the enemy moves in random directions until it finds the target again.