Weighted Random Enemy Spawning | AI Series Part 20
Published: 06 Jul 2021
In this tutorial I show how to add a new EnemySpawnMethod - WeightedRandom. I will show how to define a ScriptableObject to configure the bounds of the weight for an arbitrary enemy that is then used to spawn enemies. We'll refactor the EnemySpawner to spawn with this method, and use the new ScriptableObject instead of directly using EnemyScriptableObjects.
This configuration-driven approach to the weights allows you to be flexible in designing different scenarios for your players. Maybe some levels should favor particular enemy types, or maybe as more enemies become unlocked, you weight the new enemies to have a higher weight since they're more challenging.
In Llama Survival I implemented this exact same system to have some bosses favor spawning on specific levels, and also generate more dynamic gameplay by allowing me to customize the zombie spawn weights to control difficulty.
As usual with the AI Series, we're using the NavMesh Components: https://docs.unity3d.com/Manual/NavMesh-BuildingComponents.html not the built-in navigation system.
🔶 ALL THINGS LlamAcademy now available at: https://llamacademy.dev/support including latest tutorials, courses, ways to support, and more! Check it out 🙂
👨💻 Get the FULL FREE PROJECT on GitHub: https://github.com/llamacademy/ai-series-part-20/
🏷️Save 25% on the ultimate C# IDE: JetBrains Rider with code LLAMACADEMY: https://www.jetbrains.com/store/?section=personal&billing=yearly
Some links may be affiliate links, which at no additional cost to you, gives me a small portion of the purchase.