Powerups Phase 2: Happy Trails To You!

One of the issues I mulled over a bit ago was how to differentiate *which* asteroid has a powerup and which doesn’t, so the player can scoot on over to target one that does instead of randomly hope it contains a powerup.

In the very original pre-alpha version of the game (called Graviton back in 2008/2009), I used simple geometric primitives to display the objects (thus, an asteroid was merely a circle).  I inscribed a smaller white circle in those to indicate a powerup is contained in said asteroid.  This time, however, I figured a more interesting way would be to use the power of Unity’s built in TrailRenderer system.  A very handy feature that allows you to set up “trails” (insert LSD joke here) on objects, and the system takes care if it all for you (well, drawing and stuff, you have to make sure to enable it at the right times and such).

So, I got that feature going well enough.  Currently I only have the “autofire” powerup spawning at a given time (black hole radius = 5, for those who are curious).

At first I thought all I had to do was work on incrementing the powerup and the spawn trigger rule.  But I forgot one thing.  I have to reset/delete the “autofire” powerup from the original asteroid.  Since everything is recycled (for memory efficiency), it means that when I respawn the asteroid that contained the autofire powerup, it still contains it, as I didn’t actually remove it from the asteroid.  This in theory shouldn’t be too hard, but you never know.  I think it’s simply a boolean or an int that indicates the powerup (I’d have to look at the code but it’s all closed out now).  Then when the asteroid is “destroyed” (recycled to the asteroid pool of objects), I just reset that information so it looks as though it contains nothing.

Anyways, I’m pleased that I got this done within a couple hours of awaking 🙂  Tired as hell, need some coffee, but at least it’s a nice start to my day…

AutoFire Powerup Is GO!

Today, after a long vacation and an unfortunate turn of events regarding my leg (I may or may not have a torn ACL in my knee, have to wait and see how my own self-care works and if it’s not getting better call the doc for an MRI), I hopped on the Killing Horizon Express and rode that puppy to what seems like a good start to powerupland!

I have now officially

1) embedded the autofire powerup into an asteroid at a given trigger (black hole radius of 5)

2) released the embedded powerup upon destroying said asteroid.

3) set powerup flying into space

4) detect collision with ship

5) upon collision with ship, activate autofire

There is much on the backend that needs to be done before implementing further powerups.  In order to prevent powerups spawning over and over and over, I have to create a rule that makes it spawn once until either collected or destroyed.  I don’t have anything to reset that (such that if the powerup flies off screen, for example, or some other reason) lets me respawn the powerup or go to the next one.  I think I would like to add a sound play when you collect a powerup.  I need to create the voice effect workflow and make sure I can have a consistent voiceover effect (like my killing horizon, however, I don’t have that workflow saved, so I can’t recreate that sound exactly).

Either way, this is definite progress.  Sometimes all you need is a little break from things to get back into a working state.  I was banging my head against this for a while – I had most of the structure there, and now that I came back with a fresh head, it all fell into place (after a little bit of work).

Back in the Saddle

Well – I’m going on vacation in a couple days, and I wanted to see if I could get a little further ahead in the coding department, and thankfully, I did.

It’s a real brief start.  I started the powerup system from scratch.

It’s a little better than it was before.  Right now I have it spawning a powerup, and I can spawn each different type of powerup.

The spreadshot icon is a bit crap, so I might need to redo that one.

The one problem I’m running into now, is that while i have it so it doesn’t continually spawn the powerup (that is, it spawns it once, and it’s done spawning… in theory), after a while, I am respawning them again.

What appears to be happening is that when I shoot an asteroid that has a powerup inside, I release the gameobject of the powerup (that is, I instantiate a copy).

Thing is – if you’ve read this blog’s earlier entries, you’ll notice I mention creating a spawn pool of objects.  In this case, what’s happening is that in my pool of asteroids, I recycle a “dead” asteroid and make it alive to come back on screen (this way you’re not continually destroying and creating new objects, just deactivating them and activating them – which is much cheaper to process).  When you recycle your asteroid, you’re supposed to reset it all.  I think what happened is that I forgot to reset the powerup object, so when the asteroid gets recycled, it appears that the powerup is still inside, and thus when I shoot it, it spawns again.  In theory, that should be an easy fix.

My next goal is to implement a proper system of spawn/release points.  That is to say, the conditions under which a powerup will spawn.  I have the first few powerups ready:  Autofire, Spreadshot, Healthup…

Once I get them spawning at the proper points (and not respawning on recycled asteroids) the next goal will be to implement the powerup abilities themselves.  Or rather, so when the ship collides with the powerup icon, it activates that ability.  For auto and spread and bullet-power-up, it’s easy enough, as I’ve already got those things coded (woot!), it’s just a matter of changing my current system for activating them (pressing certain keys on the keyboard, mostly for testing purposes) to the collision method.

One thing i notice is that some of the powerups I need to resize for them to look decent, which is no biggie.  I think I might end up adding a “trailrenderer” to the powerups as well.  Just so they stick out a bit more from the background noise.  I’m already planning on doing that with the asteroids that contain the powerups (so the player knows which asteroid they should be gunning for if they want that precious object).

Then it’s going to be a matter of getting all the powerups spawning properly at various points, and tweaking that.

I think I want to change the rotation speed on the powerup icons as well.

In some ways this was easier than I thought – I think I just needed a bit of a break and a fresh mind going in.