The Boss Enemy, Part 4

Objective: Give the boss two more attack patterns.

Today we’ll give the boss an alternate laser volley attack, as well as the ability to shoot missiles. To help place these lasers and missiles in various locations, we’ll add some empty “turret” objects to the boss that will just stay at the positions we would like the lasers to appear at.

This allows us to visually see where the lasers will appear, and set them up in the inspector.

Now we can setup some variables the same way as we did for the laser fan attack. We want to keep track of how many volleys we’ve fired, and when we’ve fired them.

LaserTrackingAttack.Setup

The Act method will move the boss, and if enough to has elapsed to fire a volley of lasers, it will do so. In this case, we fire volleys using the sets of “turrets” that we set up before.

LaserTrackingAttack.Act

Now firing the lasers is easy. We get a direction to fire lasers by comparing to the player’s position. Then, for each turret, we call FireProjectile, which will create a laser at the position of that turret.

LaserTrackingAttack.FireLaserVolley

The last boss attack will be firing homing missiles that the player must shoot down. Setting up the behavior for this is fairly simple, since all we have to do is set up where the missiles will appear, and instantiate them there. Then we just use Act to wait some time before looping back to the boss’ laser fan attack.

We can use the same empty game object “turrets” and create the missiles there.

The tricky part here is to actually create enemy missiles that will affect the player. We’ll need the missiles to be able to seek the player instead of enemies, if they are tagged as an enemy projectile.

We’ll also need to handle missile collisions with the player and his projectiles. Colliding with the player should deal damage to the player, and colliding with a player’s laser or missile should destroy both projectiles.

All done! Now the boss will fire a pair of missiles and then repeat the same four attacks. This boss fight now has a great amount of variety. We aren’t done yet though! Next time, we’ll work on adding a second phase to this boss so that its even more difficult to defeat.

--

--

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
Blake Zoeckler

Blake Zoeckler

I’m a passionate and talented software engineer seeking an opportunity in game development.