Author: Zachary Geyer
Beginning of AI
One of the core mechanics of Grape Juice City is giving juice out to Grape Juice City denizens. To implement this, we used crowd AI. I used Unity’s built in NavMesh system to do most of the heavy lifting so that we did not have to create an AI behavior from scratch. The first iterations of the AI were very basic. The pedestrians were organized in groups of five that would move together as a unit to help simulate a crowd. At the time it was not optimized, and the laptops that we were working on could not handle many walking around.
Optimizing
Using Unity’s profiler, the first steps of optimization were removing some physics components and unnecessary scripts from the pedestrian prefab. The reason for this was with the high number of pedestrians was causing a lot of physics and update calls. After removing these I went from around 100-200 pedestrians in the game to 1000. Next, I set out to work with the NavMeshAgent component on the Pedestrians and the NavMesh to reduce the amount of work the laptops were trying to accomplish. The main part of the NavMeshAgent that I messed with was the obstacle avoidance to reduce how much Unity was trying to calculate for all the Pedestrians. I then found that Unity had an experimental package for the NavMesh which allowed the NavMesh to now be a game object which provided more flexibility than before and reduced some of the computation power needed for the NavMesh.
Object Pooling
I hit a roadblock where there were so many Pedestrians around the map that the laptop could not get through all of them fast enough. It was very noticeable that some Pedestrians were standing around waiting for their next command or were all pooling together in specific spots. I went with object pooling to solve this problem and this conveniently also tackled spawning for the AI.
Conclusion
I have been really interested in learning about AI and this game has provided a nice opportunity to research and see it in action. The goal from the beginning to get crowd AI into the game, and I feel is complete as the player can now be joined by the many pedestrians as they walk around the city that they call home.
Comments