Throwing your player a nasty surprise! Reverse Powerups!

This was a fun challenge. Giving the player a reverse powerup that would inhibit his ability to kill my precious AI enemies!

I thought long and hard about this one… I was going to create a powerup that looked like a normal powerup and if they ran into that thinking they were getting speed they would get this. But I thought maybe a spawning powerup that the player could run into by accident. Sometimes having to choose between taking a laser or the powerup. I chose the second.What I wanted to do was when the player collided with this new powerDown was make the player slow down. I thought about reversing the keys, you know left is right, right is left.. I may still do that in fact. But for now, we will just slow the player down.

I went into Unity and found the dimensions of where my player can roam and scribbled down the X and Y numbers. Then it was just a matter of instantiating the new powerup into that area.

I put this inside the SpawnManager script I have. Pretty basic stuff. I just created a function that will spawn my new powerDOWN — I created a variable named spawnRate that will get a random number between 1–10. I also created 2 variables that will hold the random range value of my x and y to spawn on.

Once I have those random numbers I can create a variable and assign those numbers to it. That’s the Vector3 posToSpawn. Finally if the random number generated is 1 it will instantiate the penalty prefab powerDOWN.

Now I will call this new function inside of my SpawnPowerupRoutine that is only called when my spawn manager is true.

Now, inside of my Player script where my movement is calculated, I put this:

So I needed a couple of bools so that I could set my penalty powerup to false after an allotted time and also one that would stop my normal movement of the player and set it to the slower speed. I also set the bool to true in the start.

Once I have them it’s on to create a couple of more things.

I just created a function that would slow the player down (the Debug.Log was just for testing for me, ignore that)., Basically it just set the penaltyactive to true, the normal movement to false and then started the Coroutine. The coroutine just sets the slow time to 7 seconds and then once that it is done it returns normal movement to true and penalty active to false.

Now inside of the actual movement code:

So all this is doing is if the normalMovement bool is true, the movement we set up for the player is normal. If the normalMovement bool is false then we slow the player down. Now inside of the 2 if statements I had to keep in mind that we already have a speed boost. So I wouldn’t punish the player totally, if they collected that they would get 3 speed. If not, it’s 2. And that is slow!!

Finally, I created a script and attached it to the powerDown object. Inside of this it is just going to detect the collision with the player and if so call the PenaltyMovement method I have. It also has a coroutine to keep the powerDown active on the screen for 4 seconds.

And that, is that. Let’s see how this works. Just for testing purposes I changed the random spawn number to 1, 2 so it will spawn faster.

Ok that lasts a bit long. Evil or not? Well you tell me, what do you think the length the powerDown should last?

Tomorrow I’m going to think about adding some new enemies. Maybe one that has a different laser… Any thoughts on what I should add?

Come read tomorrow what I decided on!

Happy Clicking!



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