Thursday 10 December 2015

Writing a world generator - Spawning system tutorial for Unity

1 - Intro:



In this tutorial, I hope to show you how to write a script that will run when the game starts and go over your game world, spawning objects randomly to represent terrain and items/world objects.

It should, when finished, look like this:





Monday 23 November 2015

Learning Unity Multiplayer - So much fun it hurts.

Developing multiplayer (or networked) video games is weird.

Like, stupid weird.

Only just started learning Unity networking and although I've been doing the game dev thing for a few years now and I've never encountered bugs like this before.

To give you some idea, consider what a multiplayer game is actually doing. When you play a game online (or over any network) with other players, all you're really getting is a clever illusion of a shared experience.

Imagine Monopoly.

Normally, to play it you'd all sit at the same board, using and looking at the same houses and motels, rolling the same dice. When you take the hat token, you're using the same physical hat that another player could have used. You all share the same experience but also inhabit the same 'space', you're all present in the one world together.

You would imagine this would be the same in the context of a video game. Sure the board would be a virtual representation on a screen but the other players are still looking at that same board, you take the hat, then you get the token from the same pile the other players choose from, right?

Nope. It only pretends that this is what's happening.

To continue with the same example, the difference would be that, instead of using the same boards on the same table, etc, what's actually going on is you're all sitting at different tables with a different board. You all have your own token and on each board is a copy of that token, representing you and your actions within the game, only it's not the same token you're looking at, it's the token from the other players pile, just pretending to be you.

Any time one of you does anything that might need to be known by the other players - e.g. they might not care where your dice moves when rolled, but they'd definitely need to know the number it gives you or how many spaces you move - you give all that information to a referee (the server) who goes to all the game boards and updates them to reflect the changes you just made.

All you see is a 'copy' of the game, with any changes made being replicated to all players so they can keep playing an up to date game on their own board with their own tokens and paper money.

Why is this an issue though?

Well, let's imagine that a player forgets to notify the referee of something. Such as 'Hey, I just bought Mayfair'. The player has the card for Mayfair, they paid the money, as far as they're concerned, they own it. They just forgot to mention anything - or in the correct context, someone forgot to program it so they did. So, the Ref goes back, updates all the players but doesn't say anything about Mayfair. The game then becomes out of sync. It might not even get noticed until another player tries to buy it.

And what happens then?

Well, could be anything. The game only technically has one card for Mayfair, can it create and give out two for the same property? What if the player can get a card, does that then mean two players technically own Mayfair? What if they both buy houses for it? Or a player lands on it, do they get double charged? Who does the money go to? Will the bank break if there's more money in it than it expects?

One piece of information, if not sent and received correctly by all players, can have completely erratic, unexpected and seemingly unrelated results. Combine this with the fact that the above example is a turn based setup and most games would essentially have all players playing their turns at the same time - and most actions happening around 30-60 times a second - and you start to see how things can get messy and out of control.

Trying to troubleshoot why a perfectly functioning object has suddenly started randomly shooting into the air, or teleporting to another location, why things suddenly explode into a million versions of themselves, or just vanish entirely for one specific player only is a colossal pain in the ass..... if I'm being polite.

You know, I spent about 8 hours the other day trying to work out why a giant rock would block the path of one player but not another. Then another 3 rewriting everything to make it work in a completely different fashion than how I'd originally intended because: 'Fuck it! New plan!'

So why do it?

Making games (like most creative art forms, I'd imagine) is like being able to give the gift of your favourite fantasies, memories or dreams to your friends for them to enjoy. A world of your own for others to see. An opening up and sharing of the imagination, constrained with rules of your own choosing, for other people to wander in and experience.

It's the creative medium I enjoy the most and now I'm finally figuring out how to let people experience it together.

It's awesome. Why wouldn't I do it?!

Saturday 30 August 2014

Current Features and How-To-Play.

I'll be providing a few copies of my game for testing to some friends shortly. For ease, the below is a guide listing the items and features in the game and how they're used.

Friday 29 August 2014

Trading System!

After what feels like a massive amount of work, the Trading System is finally in place!

Now, the player can purchase or sell various goods from the space stations. Screenshots follow.