Programming - Boss Fight #1

The very first boss fight for Super Street Skate that you might run into could be the Radiation Monster. I say "could", because the game wouldn't be very random if you had the same boss fights in the same order, would it?

I'd like to almost apologise up front: I don't claim that ANYTHING in this blog post is the correct way of doing anything. In fact, over the course of making this boss fight I learned more about how NOT to do things than how I should do things.

 Don't do this. Make it look nicer.

Don't do this. Make it look nicer.

Anyway, on to the programming. This took a whole bunch of learning Unity 5 things on my part, and of course, the place to go to learn about Unity programming is the unity script reference and the manual for the in-editor things.

First thing is first, the boss fight had to be designed at some point, so Matt and I sat down and discussed what we'd like in the boss fight, and how it could pan out, and we wanted something that threw barrels, spit acid, split into two and could regain health, but was fairly fragile.

Next it was onto the core programming. I wanted to create a system that could handle any boss that I threw at it. Here's what I came up with:

That's a lot of the main functions I used, and that whole block of virtual functions feeds into a big state machine somewhere hidden secret in that code. Showing it would be a spoiler for how to game the system, after all!

So the virtual functions are then defined on a boss-by-boss basis, and everything then gets handled by the aforementioned state machine. Sounds simple right?

 My face, working everything out.

My face, working everything out.

Next came actually programming functionality into the boss. That was mostly fine, create objects by instantiating them, take damage from the player, deal damage to the player etc. The real doozy came with animations, and how to make things in the scene at the exact right moment in an animation. At the time, I settled on invoking a function after the right amount of time, but now in hindsight, what happens if the player pauses the game midway through? They get smacked with a barrel from nowhere when they unpause because that Invoke() doesn't care about the game being paused.

My first idea for a solution to this was to apply a script to the animations themselves, so I could just set states in the state machine from there at the right time, and cause certain events to happen, like the Instantiate calls. I could also find which Monster was the one throwing or spitting something at you and set its state accordingly (there can be two bosses in the arena at once, don't forget).
This is wrong. Don't do this. EVERYTHING gets messy when you do this. Keep everything to do with an instance of an AI contained in that AIs script. Make that script work for x number of an AI, and your life will be happy. It took me far too long to realise this.

Now, after we got feedback from the people that played our game at Insomnia (Thanks a whole bunch by the way!), we found that aspects of the boss fight weren't particularly great. If you got too close to the boss, you could kill it easily as it doesn't have a melee attack, and won't attempt to kill you. Also the "Dance Floor" as it's affectionately called was too unclear on what it actually does, which is damage the player if they get too close, and the split wasn't obvious at all, which led to players just getting nailed by huge metal barrels from nowhere. 

And thus, the Radiation Monster fight has been redesigned into something a bit more interactive, and clear on the objectives. For now, the improvements are on the back-burner, while I work on boss number two...

Speaking of which, here's something pretty to look at!

Posted on January 22, 2016 .