Is it the end of the search as a way to obtain information?

2020 is a year many of us want to get over very quickly. Even more so if we listen to the non-stop news cycle. How people get information is no longer something people “search” for, but…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Giving our Enemies an Adjustable Chance for a Shield

Hello again! On the train of adding challenges for our player from the last post, let’s add another layer of difficulty. We’re going to give our enemies an adjustable chance to have their own shield. There is a pretty old joke that goes around when it comes to games about healing. The player may heal themselves a hundred times and not think anything of it, but when the enemy does it too? Well that’s just nonsense! But we need to challenge the player in different ways. Pokemon is a prime example of this. You might be in a tough battle with a gym leader and think you have one of their pokemon down, when all of a sudden they use a potion. While we would never give the enemy so much healing the player can’t overcome it, we’ll definitely adjust it to feel in line with what the player would expect. For that reason we’ll only let enemy shield take a single hit. This is a balance issue for our game based on player response time and limited ammo. If the player had to use 4 shots to down an enemy, that would chew through their ammo and take too long, assuming it was just a regular fodder enemy.

Your next step, just like on the player, is to set the shield to inactive, because we’ll activate them by code! Most of our work today will be done in the Enemy script. First we’ll both make the chance at having a shield, and then we’ll get a reference to the shield itself.

First you’ll see that we’ve made a serialized field for the percent chance. This will let programmer decide how big a chance the enemy has to have an active shield. The next part you’ll see is a serialized field for the shield game object. Then we created a bool to check if the shield is active. After that you’ll see in the void start that we have added an if statement that checks a random number between 1 and 100 against the programmer’s chosen percent chance for the enemy having a shield and turns the bool on if true.

Let’s get things setup in the inspector.

For this enemy it will have a 20% chance at having a shield, and when that 20% chance is met, the if statement will run and the shield will be activated. Next we’ll need to make the shield actually take a hit for the enemy. We’re going to go into the “private void OnTriggerEnter2D(Collider2D other)” on the Enemy script. For the enemies that have a chance of having a shield we’re going to add some code into the part where we check if they collided with a player’s laser.

When the enemy hits the laser, the code will see if the enemy had a shield active by checking the bool. If it did, the enemies shield will be turned off and the code will stop before the enemy is destroyed. This will mean then enemy has to be hit again to be destroyed. We only did this on the laser collision because we still want the beam attack to be able to destroy enemies on collision no matter what.

Can we see it in action?

Short and sweet.

Ta-da! You’ve provided a new adjustable challenge for your players. I hope after all the work we’ve done so far you felt pretty comfortable about this one. Great work and I’ll see you again soon!

Add a comment

Related posts:

DEXTF Liquidity Mining Incentive

After going live about 10 days ago, we’ve received a fair amount of feedback from investors on how the crazy gas fees were preventing people from both creating funds and in general to interact with…

The Great Pretenders

It is fairly safe to say, or potentially not, depending on whose reading this, that America is not a democracy. There will be many of you who read this and will no doubt have an arguement against…

Designing Accessible Builder Apps

Global Accessibility Awareness Day (GAAD) highlights the importance of Digital Access and Inclusion for over 1 Billion People with Disabilities around the world. We enthusiastically celebrate GAAD at…