A creator named NovemberDev made this game without having performance in mind, yet his enemy AI, while being relatively simple, is still extremely fast: his game can have hundreds of enemies all moving and colliding around without too much performance issues.
The only sources of lag in his game are literally the enemy sounds; if you delete all the sound nodes and make the game mute, it runs incredibly smoothly with a large amount of enemies.
like here's the enemy.gd: https://github.com/NovemberDev/novemberdev_soulslike_darksouls_godot/blob/main/Scripts/Enemy.gd
I'd like to replicate his methods, only one problem....he doesn't use areas to detect the player the player position, he uses the tree node.
Autoloads : get_node("/root").add_child(player)
Enemy.gd : distance_to_player = Globals.current_player.global_transform.origin.distance_to(global_transform.origin)
I tried using the same player detection, it was actually my very first method of doing it.
The problem is that the Godot documentation suggests that to save and load the game, one must delete all saved nodes before loading as to avoid the nodes being duplicated every time you save and load.
Straight from Godot docs:
var save_nodes = get_tree().get_nodes_in_group("Persist")
for i in save_nodes:
i.queue_free()
so whenever you save and load the game, since the enemies are keeping track of a specific node, the game will crash because the node that the enemies where keeping track was deleted and replaced... it doesn't matter that it is literally the same node, a complete clone... godot doesn't recognize it and the game crashes.
So for now, I tried using multiple area nodes, each one with a collision attached to it. That was a bad idea. I also tried to maybe not use area nodes but just create an area in code and use it to define distance... and that wasn't such a big improvement, not at all actually. Rays just make the enemy agent feel like it is blind, and to mimic the effects of areas you have to add dozens on dozens of rays in all directions, otherwise the player can easily hide behind a blade of grass and become invisible to the enemy.
So what other ways are there to detect players/prey/physical things that AI is supposed to detect?