[SOLVED] How to do PowerUps Correctly

Hello guys,

In an effort to drive myself completely insane, along with all my other todo things in Block Breaker like getting the sounds working correctly, trying to change to way the ball bounces. I decided that I want powerups in the game, also another thing I know nothing about. So before I go too far and get totally lost with the actual powered up ability. I need some pointers on how to get the powerup to drop from the brick that’s destroyed.

Now, what I’m thinking is that I need a brick that’s tagged with the name “powerup” so that just before the brick is destroyed it drops a prefab item. Meaning the counting of items will need to include the “breakable” tag and “powerup” tags. Would this be the correct way of going about it?

And with the prefab item, in the original game as the “powerup” item scrolled down the screen it “rotates”, well it gives the appearance of rotating as it steps through it’s images. Now because we don’t really have access to X and Y screen co-ords we really can’t control the descent of the item, so, would the best way to get it to descend downward to our bat be by using our friend gravity? And I have no idea as to how to scroll through the images as it’s descending - I have a sprite sheet sliced ready for this - to make it look like it’s rotating. Does anyone have any pointers on this? We have changed the images of a sprite and spriterenderer using an array but only after an action has happened, this will have to occur automatically and not so quick as to be unreadable or turn into gibberish.

As always here is a big thankyou in advance.



I did powerups both in Block Breaker and in Laser Defender I did them a bit differently though but I hope I can still offer some help. I think you counting of items is the correct way. And in your code you can have it so that when a brick with the tag powerup is hit it instantiates a prefab powerup.

You can actually have access to the X and Y coordinates. To your powerup prefab you could add a rigidbody and you could then add a velocity value to it to control the descending speed. Gravity should work too I think. Further on the rotation of the powerup you could have an animation that goes through the images or I think you could also have a loop in your code that goes through the different images sequence. You could load the images in an array and change the index number in your update method.

Ok, I did as you suggested and it functioned pretty much as I anticipated it might, it spins way too fast, I only have 8 separate images index range [0-7] and I don’t know how I could slow in down. Seeing as the Update function, for lack of a better word updates every single frame :slight_smile:. Those images are flying through.

I did try an attempt at using yield WaitForSeconds() but, that is way above my paygrade.

So yo you (or anyone else for that matter) know how I might slow it down?

You could add a float variable called countdown and use that as a timer of sort. Set it at the start at for example 5. Then in your update method decrease that variable via something like variable name -= time.deltatime then where you are changing the index of the image in the array add an if condition to only change the image when your countdown variable hits 0.

This is probably making things more difficult than it should be so I’d be curious as well what others thoughts are. Animation may be easier for this.

1 Like

Animation? Hmmm, never even considered that, could be a good option. I’ve already sliced the images, so, that shouldn’t cause too much of a hassle and I might be able to control the speed better. I’ll see what I can come up with - mind you I’ve never done anything like this so it’s a bit scary :cold_sweat:.

EDIT: It actually wasn’t that hard, and the results worked a treat, and the speed of the animation was just about perfect - no real need to get into the nuts and bolts of the animation system to modify it :grinning:. Might mess about with it in the future. I’ve got so many other things to do first.

Thank you so much for giving me the idea :sunglasses:.

Of course, in the spirit of openness and this forum, if anyone wants to know how I created the animation on the prefab then I am more than willing to tell how it’s done - it was quite easy :smiley:.

Sure. I’m thinking about power ups as well. So if you can share your story, that would be interesting to read.

Ok, no problem. But I must reiterate that it is only about how I created the power-up and getting it to fall from the sky down to our ship. Actually implementing those power-ups is what I have been exploring since I wrote this post, and it goes in fits and starts. Having never done a game before means I really nave nothing to base it on :smirk:. I am interested in having 3 powerups: Extend, Laser and Disruptor (ie 3 balls on screen).

Next post making the power-ups…

Ok, here are the steps to create the powerup. If you are extremely creative there make your own sprite sheet and disregard many of these steps. Unfortunately, I am not that creative :slight_smile:.

  1. Go to Spriters Resource - use google - it will show up.

  2. In the search box type: Arkanoid. On the results page look down the page for subheading “Game Results” and further down “Arkanoid: Doh it Again” and click on the image.

  3. On this page goto subheading “Miscellaneous” and then subheading “Powerups” and click on that item.

  4. A representation of the Sprite Sheet will appear. Look for “Download this Sheet”, it’s not immediately apparent where it is :expressionless:

  5. Get the downloaded file and place in in the correct Unity Assets folder - I used the Sprite folder. Luckily with this sprite sheet, we don’t need to do anything with regards to transparency - I use Gimp and it’s not at all intuitive how to do transparency - I’ve used in numerous time and still use the incorrect options. One day I will write them down!

  6. Next, open up Unity and goto the directory where you dropped the sprite sheet and click on the file

  7. Now in the Inspector a new window will appear, so go to the “Sprite Mode” and click to change it from “Single” to “Multiple” - and change Pixels Per Unit to whatever suits your needs, I chose 25 to make it a lot bigger.

  8. Click “Apply” near the bottom of the window just to be sure it gets done now.

  9. Next, click on “Sprite Editor”. Now in the small box that appears in this new window click on the “Automatic Selection” and choose “Grid”.

  10. Change the value in x: to 16 and change y: to 8. And leave all other values. Yep, these are really small graphics without changing the pixels per unit. And click “Apply”. Hard to find up there on the Right Hand side.

  11. Back in Main Window create a empty Game Object - rename it in the Inspector to whatever you require. I will do the first one as an example - so I renamed it to “Break”.

  12. “Reset Transform” as always.

  13. Go back to sprite directory - or wherever you put the sprite sheet - and on that sprite sheet click on the right facing arrow button - to open up that sheet. There are a lot of images in there. Now find the series of “B” images that make up the rotation effect of the powerup - there are 8 in total.

  14. Hold “Ctrl” - I use Windows - and left mouse Click on each of the 8 images separately. After that drag these images up to the “Break” game object in the Hierarchy. Make sure it’s directly on.

  15. If you dragged it exactly on a “Create New Animation” dialog will appear, so save the animation with whatever name - I used “Break”. Now you can cleanup this an put the animation file and the Animator in another directory, but, I couldn’t be bothered with that - not confident enough to play around with that stuff yet.

  16. Now move your “Game Object” or Break in the scene view where it will be able to be seen and press “Play” you should see the animation.

  17. In that game Object look for the “Sprite Renderer” component and on “Sprite” where it says: None (Sprite) click on that circle and choose one of the 8 images that make up the animation. I chose the first one with the “B” showing.

  18. Now to have the item fall down due to gravity, go to “Add Component”, go to Physics 2D and add a Rigidbody2D component.

  19. Now add a Collider2D component also from the Physics 2D selection - you pretty much have to choose “Box Collider 2D”.

  20. If you want a bit of a laugh, leave the settings as they are, and run into the falling powerup with the bat and ball or better yet hit it with the ball - it’s hilarious. Otherwise you will need to set it: “Is Trigger” in the Box Collider 2D component. And set up your OnTriggerEnter2D in your scripts to deal with the collision between the paddle/bat/ship and the powerup and removing the powerup with Destroy when required.

I haven’t moved onto that yet, I have just made the powerups “Is Kinematic” to leave them on screen. I have been busy adding the shooting functionality (laser - “L”) without actually needing the powerup, so, it will be easy to wire them up when the shooting is working correctly. You could also turn this into a prefab - that’s what I did for when I need to delete the original from the “Scene View”.


Privacy & Terms