Adding a Shockwave Powerup (2D Space Shooter)
Recently implemented this ‘shockwave’ weapon to the 2D Space Shooter I’ve been working on, with the intention of it being the most powerful (and hopefully most satisfying) powerup in the game.
The shockwave object currently consists of a ‘Radial Shadow’ sprite (that was included in this Modern UI Pack I’ve been using across a couple of projects recently), a Circle Collider 2D, a Rigidbody 2D, and this ShockWave script. It’s quite a short and simple class but it seems to get the job done:
I tend to change the duration to 1.5 in the inspector, and set the End Scale to 7 in both the X and Y axis. I think this gives it a short, sharp effect, clearing the entire screen in an instant. I’m using a coroutine, a while loop, and a Vector3.Lerp to have the object rapidly expand over the specified duration. I tend to use these three in combination in a lot of the projects I’ve worked on, as it gives me some fairly smooth transitions between two states. And while I’m not doing it here, I often pass a ‘duration’ float into the coroutine and into the Lerp, letting me control the speed of a transition from wherever I call the method.
I’ve given this GameObject its own ‘PlayerShockWave’ tag which can then be registered by any enemies or asteroids on the screen. Unlike other weapons in the game, the shockwave doesn’t get destroyed on colliding with an enemy, but instead continues on its path until it’s cleared the screen. I’m also coupling this with a variant of the standard explosion sound, reducing its pitch from 1 to 0.7 in an Audio Source component.
Hopefully the visuals, sound, and functionality of the powerup (essentially a last resort/saving grace for when the screen’s busy with enemies) make it fairly satisfying to use 😉