Hey everyone, so for the past month I’ve been working on a game that will feature hundreds (probably around 500 - 800) of individual animals controlled by AI on a purely tile based world. They all need to eat, drink, stay away from predators (such as the player) etc. All of this requires a metric ton of pathfinding. Now I’ve achieved what I wanted from the pathfinding without many issues. Animals are able to navigate through the world without running into each other, they won’t freak out if their path is blocked, it’s all working smoothly. Except for the fact that the sheer performance drop, once there are more than 40 animals on the map, is substantial. If I have 60 animals on the board, it can take up to 8 seconds per frame! (with 40 I get around 90 fps).
All of these animals not only have to search for food, water, and other resources, but they also wander around when they have nothing to do. This means that at almost all times, an animal is having to path to its destination. This is the reason my computer is having such a difficult time keeping up.
I’ve run various performance tests and improved the system, but it doesn’t really make a big difference. I tried only updating 30 animals per frame, but naturally this caused every animal to slow down considerably.
So my question is. Is it even possible to process so many entities? The game revolves around the fact that entities never spawn or despawn. This is to provide the realistic world where even the smallest change to the environment can cause a chain reaction. Such as an oasis drying up that causes all the animals nearby to migrate to a new source of water. It also allows for natural consequences if the player makes a mistake (such as accidentally killing too many squirrels causing them to go completely extinct).
Thanks