Nerd For Tech
Published in

Nerd For Tech

Balancing Powerup Spawns

Now that we have added in a couple new types of powerups, let’s look at how we can balance out the rates of the spawns so that we have a much higher chance to get ammo, and a lower chance for health based powerups. If we kept the current rates, we are looking at a ~16% chance that we will spawn ammo, which can feel like forever in some cases when the player is out of shots.
There are multiple methods that can be used for this process, however in this case, we will use a switch statement within our spawn manager script. We will first create a new variable to work with:

With this value, we can go into our SpawnPowerup routine and give it a random range value that will be created whenever the routine starts up again:

We will add the debug.log for now to see the values that roll in our game when we play and make sure they properly match what should be spawning with that number. Next, we will start to make our switch statement to determine the powerup that will spawn:

What we can do with our switch statement in this case is forgo the range for each case and type it all in the initial statement. Then, whatever the value becomes, it knows that you want it to be the specific power up and it will call that case. As well, if it happens to be 64, it will call the lowest possible case, which in this case is Ammo. Health and Tsunami technically fit into that value, but switch cases will choose the first available option to pull from.
Now that we have all of this put in, we can take a look into how it looks within our game and see if the numbers match what we want it to be with our desired cases:

As we can see from above, the powerup we want to spawn is showing up if it’s value is rolled, and no extras come in cause they fit the criteria.

--

--

--

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Recommended from Medium

This is how we made Furlenco app clone in just 4 day’s

Training a Corporate Team on Python: An Insight

Kubernetes Tip: Max Pods Per Node

How to Install .Net Core Runtime in Service Fabric Using Terraform

Data Center Migration : Strategy, Process and Solutions

Eleven Finance — A PancakeSwap migration update

Prepare GCP Associate Cloud Engineer Certification Exam — 1

Update: Node Authentication Problem

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jordan Evans

Jordan Evans

More from Medium

Journal 148 — Unity Project Development, 2.5D Shooter

Building A Stealth Game — Helping Your Guards “See”

Unity Basics by making a project

Doing basic unit testing in Unity/C#