• About
  • Gallery of Images
  • Archives
  • Categories
  •   Unity and MMO experiment – advantages of rapid prototyping

    19/09/11 - 20:31

    Many, many years ago I was an avid user of Second Life. The thing I loved most about Second Life was being able to build and create things for other people to enjoy. I spent many an hour on my own Sim, creating fantastic buildings and crazy script inventions.

    The Grid

    The Building Grid - and an untexture dwarf or viking midget, can't decide which is cooler.

    As phases come and go, I slowly got tired of Second Life. But, I still enjoy the feeling of creating things for other people to explore. I get a giddy thrill every time someone finds the easter egg in SpaceOreMiner, and decodes the cryptic message and sends me a mail about it.

    Some Cubes

    A collection of the default cube with the standard texture

    This weekend, I found a box of old designs for various buildings I had planned on building in Second Life, but never got round to creating. So, I thought to myself, why not create some of them for others to look at? Alas, my Blender skills suck, and anything I produce with Google Sketchup tend to look like something a cat may have vomited.

    So, I asked myself, why not build my own 3d environment, similar to Second Life, to allow me to create the buildings? I opened up Unity and a text editor, and got coding.

    A Cube Selected

    A Cube selected, and the god awful UI, the red colour indicates this is the currently selected object

    Five hours, and several beers later, I had the shell of an environment created. Building designs forgotten, now I had my own little world to build and play in.

    It is still very, very crude ( think early proof of concept ) but I am pretty happy and very pleasantly surprised that I could create such a ( on paper ) complex application in such a short time. I always seem quite surprised when I produce something quickly in Unity, perhaps I should stop being so surprised by it 🙂

    The world consists of three parts – A webplayer, a PHP backbone and a MySQL database. The webplayer allows anyone the ability to add and create objects within a 3d enviroment. The UI ( which is god awful at the moment ) allows full control of the size, texture, position and rotation of all objects spawned within the world.

    With the first version, you would hit create, an object would appear which you could type numbers in to alter the object. This felt pretty clunky, so within 20 minutes, I had arrow’s which would let you adjust the object visually, the object reflecting whatever attribute you were manipulating with the arrows. After 10 minutes of playing with construction, I built the Clone button, which when clicks clones the currently selected object – suddenly building got a whole lot faster! ( this again shows the best way to develop anything is to actually use it !) After another 10 minutes, I added some basic textures to the objects, allowing you to change the assigned textures from within the UI. This all fell into place so quickly, it was really a rather pleasant surprise.

    Textures

    A massive collection of six ( 6 ) textures !

    The meat of the project is in the Save World and Load World buttons. Every object inside the webplayer is tagged with the tag ‘building’. This allows the Save World button to very quickly located all the objects within the world ( via the GameObject.FindWithTag call ) and record every attribute of each object. This information is then formatted in a certain way, and then it is submitted to the PHP script via a WWW call ( via the amazing WWW class ) . The PHP script records this information, changes it into a database friendly format, and then saves it within the MySQL database. Sweet.

    Clicking on Load World calls a different PHP script, which reads this information from the database and returns it to the webplayer. The webplayer takes this information, spawns the correct numbers of objects and then alters the attributes on them to the database returned information.

    With these two functions working together, it is possible to create a persistent online world. I’m sure there are some limits somewhere, but the biggest world I have created had just over a 1000 objects in it, with no really delay in loading or saving – anyone who has built in Second Life knows that a 1000 prims is a helluva lot – with that many prims, you could construct an elaborate Gothic castle ( or a single woman’s hair piece, heh). Currently, the only objects that are able to be created are cuboids – but with the code base as is, it is very simple to add anything as an object, and due to the way the world is constructed, anything that can be an object within Unity can be added – so any 3d model basically 🙂

    A trilithon

    A trilithon with some randomly rotated cubes next to it

    I’m not sure what I’m going to do with this, I have a vague idea of a Minecraft type environment – but without cubes 🙂 Allowing anyone to build any thing they can imagine. The project doesn’t actually have a name as it was more an experiment ( well I like to think of it more as a code doodle ) than anything – but I think it could be a very useful addition to my arsenal of solutions.

    lamentconfig
    Share

    2 Responses to “Unity and MMO experiment – advantages of rapid prototyping”

    1. Jim says:

      Hey there! I stumbled onto this post after quite a bit of extensive googling… I’ve been trying to find advise or tutorials for creating objects dynamically like you’ve described and achieved. Do you know of any assets that do this? And furthermore, have you continued developing this project? I’m a bit of a newbie to Unity, but I’ve been pouring over your descriptions and noodling on how I might be able to experiment with something similar.

      • lamentconfig says:

        Wow, sorry for the late reply, not been blogging recently alas. This was done in an old version of unity and not sure it will port very well to a new version, I’ve been focusing my attention more on html5 than unity for a while now. This was pretty much a proof of concept, but think I’ve got a webplayer demo I could put up somewhere if you want to have a play with it. Asset wise, everything here ( with the exception of the dwarf ) was built from the ground up, they are basically prefabs that can be spawned with parameters. If you have any questions, feel free to drop me a line 🙂

    Your Reply


    %d bloggers like this: