Galaxy Shooter Phase 1! Lay down the framework! First challenge — Speed Boost.

Wow! I made it to the end of the 2D game course but now it’s time to put my knowledge to the test. I’m being given two rounds of challenges that will be related to Unity certification. I’m excited and a bit intimidated but I will climb any mountain to reach the goal of becoming a rock-solid game dev, so let’s do it!

This challenge sounds simple enough. When a player hits a shift key, make them go faster until they let go.

Well, to begin with, we already have a speed modifier in our Player script that is activated with our powerup, so let’s just use that.

Initially, _speedBoost is set to 1 since it’s constantly being multiplied with the players speed and then its given a 2 to double the speed of the player.

We’ll need our game to be constantly checking the status of the shift key so we’ll put it in the Update() function. Better yet, I’ll put it in its own function, CheckBooster(), which I’ll put in the update function for better readability.

Doesn’t this look better than a bunch of code spread out like a bunch of legos?

So what I needed to figure out was:

>Check if the player hit the shift key

>If they were, change the boost variable to something larger. I put 3 to make it noticeable, but for a normal game build, it will be 1.5, not as fast as a powerup, but better than normal speed.

A simple if then seemed to have done the trick for this challenge:

There’s no general ‘check both shift keys’ in Unity, so you need to tell Unity to check if either the left shift key is pressed OR the right shift key is pressed, then activate the speedboost by changing the variable to 3 for 3x the speed!

So let’s see it in action!

Working good!!! On to the next challenge: Shields!

cartoonist, game artist, and wanabe gamedev.