‘Beamer’ Enemy Type (2D Space Shooter)

I recently implemented a more formidable enemy within the 2D Space Shooter: ‘beamers’. Instead of firing lasers at the player, these fire a beam for about 1.5s, and instead of moving directly down these move diagonally (and descend slower than the typical enemy type). This should allow them to cover as much ground as possible with their beams, and since the player can only fire upwards they’ll need to wait for the right moment in which to take them out (especially if the screen starts to get crowded).

I’m currently controlling these using a ‘BeamerMovementBehaviour’ method, which will check to see whether their transform.position.x is less or greater than a minimum or maximum value. If it is, I’m flipping a bool’s value (_moveLeft = !_moveLeft) and then use this value in an else-if statement to run the transform.Translate method. This method currently takes in a Vector3 of -0.5 on the x (or 0.5 if it’s moving right), -0.5 on the y, and 0 on the z axis, which is what’s letting them move downwards diagonally.

For the beam itself, I have a ‘FireBeam’ coroutine which accepts a float argument for the duration of the beam. I’m then just instantiating the beam prefab with an offset from the enemy, parenting it to the enemy, and am then using yield return new WaitForSecondsRealtime(duration) to wait for the specified length of time. After this, I’m just doing a quick null check on the instantiated beam to make sure it still exists, and if it does I then call the Destroy method on it.

For a final touch, I looked for a suitably grating and/or slightly unpleasant sound for the beam itself — some sort of synth sound I could easily loop. I edited a Creative Commons 0 sound I found on freesound.org, then just assigned this to an AudioSource on the beam prefab and set it to PlayOnAwake and loop.

I wanted to create an enemy type which would hopefully provoke a more immediate response in the player (creating a sense of urgency), since this one can easily cause the most havoc if left unchecked, so am hoping the auditory and visual ‘presence’ of these enemies can do just that 😉

--

--

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