There's two problems with the current Outlaws game. One is that it requires joystick support, which while great if this were an Xbox 360 indie title--and, who knows, maybe one day it will be!--most PC gamers don't have a gamepad connected to their machine like I do. Secondly, even if they did, they don't have anyone locally around willing to play the game with them. Adding keyboard support as an option is relatively trivial from a coding perspective, so I decided to tackle the far greater problem first--online multiplayer.
My first approach was to purchase an asset from the Unity assets store that'd do all the heavy lifting for me. That product, called Fieldkit Readymatch, looked very promising. Unfortunately, I couldn't ever get it to work, and since its functionality depended entirely on their server, I also didn't have a way to know if the problem was on my end or theirs. Eventually, a guy from the Unity assets store contacted me and said they were refunding the purchase price of $100 and removing that asset from the store! So I guess it wasn't just me after all.
So then I turned to a product called Smartfox Server. It came recommended by a Matt Chatter who's a pro, so I figured what the heck. It's free and has a C# API, and has some tutorials that pretty much do everything I needed. However, wrapping my head around this stuff has pushed to my absolute limits. It's very difficult for me on a conceptual level, trying to keep in mind that there will be multiple instances of the game running on different clients...I know this all comes naturally to a lot of you guys, but for me it's maddening. I mean, I had a hard enough time mapping out two different control schemes for two players on the same screen!
I'm kinda pumped right now because I think I have all the functionality figured out to do what I need to do. Rather than go straight to hacking Outlaws, I did a preliminary scene. I now know how to set up zones, rooms, have players connect to those, and so on. My sample scene just has two blocks moving around, but the exciting thing is that players control their own block--and can see the other block when it moves. I still need to work out the intricacies of "interpolation" to deal with lag, but it's still a huge step forward.
My next headache was figuring out how to setup my solar system so that both players will see the same thing. I thought about it for awhile, and reckoned that really all I need to make this happen is to generate all the variables first, then just send them in a package to all the players. I got really confused, though, since there seems to be several fundamentally different ways to go about it.
One commenter suggested doing this stuff server side, which sounded like a plan to me. However, as far as I can tell, the only way to do that is with a server side extension. The example videos show this being done in JAVA. Oh, boy. To make matters worse, my internet connection has been absolute shit lately, and I wasn't able to access the Netbeans site or the Java site...Or the Smartfox Server docs for most of the day.
I decided that's a lot of trouble to go through, so then I started wondering if I could just have the first player's client do it. The game rooms assign each player a playerID, which always starts at 1, so it seems straightforward enough. I can check to see if it's player 1, calculate and put all the numbers into room variables, which I can then send out to the other players. I was able to do this successfully with a random number test, so in theory...If it works for one random number, it should for an array of them.
I'm not quite sure what's going to happen if Player 1 drops...Will the room variables stay the same or change? I guess for now I'll just automatically end the match and end players back to the lobby if that happens. I really want to have four players on screen eventually, but might have to wait on that until I get the system figured out. Even though this approach seems to work, I don't like it much, so I'm going to try again to see if I can make some headway into doing this stuff server side via a room extension.
I'm really hoping I can get this server stuff figured out, because I can imagine tons of fun possibilities. I did find six basic tutorials on Unity and Smartfox, but, boy, could I use some more. It seems odd that there isn't more stuff out there on this. Surely it's a common enough thing for indie developers.