As Star Battles was originally envisioned by our illustrious
Dear Leader, it was going to be a networked 3-on-3 dogfight free-for-all of
hyphenated awesome-sauce with in app purchase of upgrades and powerups to help
you smash your friends and enemies.
With such an inspiring vision dancing before our eyes, we couldn’t help
but dive into the project and go in search of networked gaming knowledge.
It turns out there is actually a terrific little tutorial
tucked away in the Unity documentation in the Unity Manual's Networking section. We used this to give our little space
shooter some booster rockets and get it off the ground. Then, our illustrious Dear Leader
informed us that the vision had changed.
Networking was out on our target platform. Oh noes!!!! We
should cry! But, no! Have no fear, Unity’s awesomeness
shines through again!
You see, that networking tutorial actually stepped through putting
together a basic UN-NETWORKED shooter game before it added the networking stuff
on top of it! We could actually go
right back to the same tutorial we’d used to make the networked game, and
skipping the network specific parts, create a nice little starter shooter
game.
Obviously, we were adapting it as we went. For example, SB uses rockets as the
primary weapon, so instead of the “bullets” that the tutorial instantiates and
just sets a velocity for, we instantiate an object that has AddRelativeForce()
called on it. This allows the
rockets to interact correctly with the gravity well in the middle of the game
space.
As an additional bonus for us, this tutorial was in UnityScript (a Unity specific form of JavaScript) instead of the more common C#. Neither of the programmers on SB are familiar with C#. Though, after a couple of debugging nightmares related to JavaScripts loose handling of types and my own ignorance, I'm awfully tempted to start learning C#. (The Unity Scripting Reference can be viewed in either JavaScript or C# by selecting an option on the webpage, BUT the Unity Manual can't. There were a couple of times that I wished this was not so, but alas...)
This tutorial was where we figured out how to handle health and damage. I think we even still have the same script name of "Combat," though the script has more bits and pieces to it now in SB to handle things like "Death By Planet" and the like.
Unfortunately, the Network Section tutorial's example UI used some older code that smelled funny. So, our UI to track health and display it came from video tutorials and a really helpful YouTube video. That YouTube video was especially funny because the guy making it actually took about four minutes while he was recording the video to figure out the problem we were actually having with our health bar. He set it up and tested it, and then paused for a moment as it didn't work. Then I watched him run through the first two or three things I'd tried to fix it. I was a little worried. Then he moved on to stuff I hadn't tried and didn't know about, and my hope increased. Then, he did something that seemed to work. So, I did it in my code and editor. And, boom! Health bar shrank as health decreased. Thanks, xOctomanx! Awesome logo, by the way.
Unfortunately, the Network Section tutorial's example UI used some older code that smelled funny. So, our UI to track health and display it came from video tutorials and a really helpful YouTube video. That YouTube video was especially funny because the guy making it actually took about four minutes while he was recording the video to figure out the problem we were actually having with our health bar. He set it up and tested it, and then paused for a moment as it didn't work. Then I watched him run through the first two or three things I'd tried to fix it. I was a little worried. Then he moved on to stuff I hadn't tried and didn't know about, and my hope increased. Then, he did something that seemed to work. So, I did it in my code and editor. And, boom! Health bar shrank as health decreased. Thanks, xOctomanx! Awesome logo, by the way.
Then, we stole that code and method for the laser weapon energy and the shield strength (two optional weapons that players can eventually get in SB). Right now, our UI looks kind of like obscure European flags with three stripes of color stacked behind the text, but it works!
No comments:
Post a Comment