Jun 24

Making Boccia in Unity

Boccia

After last night's fun at LUUG we thought we'd put up a summary of our talk...

The 2012 paralympics are on the horizon. As the official broadcaster, Channel 4 are gearing up to deliver a broad range of digital content to support the events, including several games. We were lucky enough to win a pitch for Boccia (pronounced 'botcha'), a ball game played in the Paralympics with rules similar to French bowls. Even luckier, our proposal to make it in Unity was approved.

Unity seemed like a good fit for three reasons. Firstly, we just knew that Boccia was a game that would work best in 3D. Secondly, the game would need a lot of ball-physics which could be handled easily with Unity’s powerful PhysX engine. And finally, we’d been looking for a project of a suitable scale to use Unity for the first time.

To an experienced 3D developer this walk-through may feel like teaching your grandmother to suck eggs, but for anyone considering making the leap from Flash to Unity, we hope we can offer a few tips and techniques...

Low-level prototype

After having a basic game design document signed off we were keen to get a prototype built as quickly as possible. This included a court, some balls and a basic throwing mechanic. The prototype was helpful both for getting a feel for the physics and for experimenting visually. Unity comes with a pack of useful scripts and game assets that allow the creation of prototypes very quickly. Even designers with little or no coding skill (erm, like me) can put together a rough sketch of a game.

Tip 1 - The Unity Asset Store is full of great packages and plugins to help designers and developers rapidly prototype their game ideas.

A very early prototype experimenting with toon shaders

3D asset creation

The prototype proved that the toon-like style we wanted to go for was possible. We were then able to push forward and produce all the 3D assets required. Strict scoping of the project ensured that this didn’t get out of hand; we’d agreed previously that there would be no human characters portrayed in the game. That left a selection of courts, medals and balls to be modelled and textured, which we were able to do in-house.

Tip 2 - Animation can be added to models using Unity’s animation editor. This can be quicker for creating simple transitions, rather than trying to position everything in an external 3D program like Maya.

Boccia medal 

Hard-mode Tournament medal

Boccia arcade mode 

Time-attack Arcade mode

Boccia wireframe 

The Tournament court before lighting

Boccia camera effect

Adding a Camera-flash particle effect

Coding commences

At this point the designer had a complete set of scenes populated with assets which was handed over to the development team to begin coding. Just like most of our Flash projects, many of the scenes were completely rebuilt in code, but having the original reference scenes to work from was vital.

Unity offers developers a choice of three scripting languages to choose from: UnityScript, C# and Boo. While UnityScript looks very similar to Flash’s own ActionScript, much of the Unity development community has now settled on C# as the language of choice, and we have as well. It’s a great language to code with, powerful, well documented and feature rich, with a choice of two great Unity compatible editors: VisualStudio and MonoDevelop.

Unity’s component based drag-and-drop editor tends to favour object composition over inheritance, but in practice we found that a mixture of the two design patterns worked best. Those of you coming from a background in traditional Flash development may find this video useful in understanding the differences between the two.

Tip 3 - Unity imposes very little structure on you as a developer, which is great for small projects and demos, but make sure you try and define your own framework when building larger scale games otherwise things can quickly get out of hand. Take a look at how the official tutorial projects have been put together for some inspiration.

Boccia scene manager

Attributes from a script exposed in the editor for easy tweaking

Interface build

A major difference in the Flash / Unity development process is GUI implementation. Unfortunately it is much more difficult to build a GUI in Unity as there are no 2D drawing tools at all. Thankfully there are some great 3rd party tools available to ease the pain, such as EZ-GUI and QuadUI. Unfortunately we had a unique requirement that none of these could handle at the time: the entire game, including all menus, needed to be fully keyboard accessible and so building a bespoke menu system seemed like the best solution. For the animated transitions, we chose to use an external library called iTween, which is Unity’s answer to Flash’s TweenMax, but with the added bonus of a visual editor.

Tip 4 - Building menus for Unity is similar to old-school HTML building; each button state needs a separate graphic. This can lead to hundreds of 2D assets being required... think very carefully about the complexity of your menus.

Boccia menu

Taking interface designs from Photoshop to Unity is not a simple task

Performance optimisation

As our first ever Unity game we wanted Boccia to be as solid as possible and play on as many machines as possible. The simplicity of our environment designs helped, but there were a few tricks we needed to employ to get the game working smoothly on the most ancient machines.

Tip 5 - Combine your meshes. The more discreet meshes you have in your scene, the more draw calls the system has to make, which is bad. Combine meshes and use a single texture where possible to combat this.

Tip 6 - Dynamic lighting has an adverse effect on performance, and leads to compatibility issues on older machines. Use Unity’s built-in lightmapper to optimise your lighting.

Tip 7 - Once your camera-angles have been established, save memory by going through your scenes and reducing texture resolution wherever possible. Halving the resolution quarters the memory required.

Tip 8 - Write a quality manager to automatically detect the player’s system performance and set the player quality accordingly. Custom flags may be added to this; for instance, restrict blur effects to high-quality mode.

Tip 9 - Try it on your gran's computer. Find the oldest, dust-ridden machine you can and load up your game. Unity has several options to emulate low-end graphics cards but nothing for lower memory and CPU capacity. We’re pleased to say that Boccia runs pretty well even on a low-powered Netbook packing one of Intel’s infamous integrated-graphics chipsets.

Find more opitiisation tips on the Unity forums

Facebook & database integration

For the most part, all the server-side development was strikingly similar to how it would have been if Boccia were a Flash project. Unity has a dedicated set of classes for sending and retrieving information over the web and can even ‘talk’ to Javascript just as Flash can do. Sure there are a few quirks - Unity and C# doesn’t seem to support JSON and it lacks a lightweight XML library - but considering it’s only on version 3 (compared to Flash’s 11) it’s pretty good.

Tip 10 - While in Flash a user’s clicks can trigger valid pop-up windows, with Unity this is not the case and all pop-up windows will be blocked, even when the user has clicked a button first. We ran into this problem when integrating Facebook Connect with Boccia and had to resort to using a HTML button instead.

Testing and tweaking

Whilst it’s always good practice to use an external testing agency to ensure the stability of you game, it was especially pertinent in this case as a) we were using a new technology and b) the game needed to be fully keyboard accessible to meet Channel 4’s requirements. Building this phase into the project also gave us some time to refine playability. Unity allows the use of external xml files, so the designers were able to tweak the AI opponents without incurring extra developer time.

Tip 11 - Unity allows the creation of pre-configured groups of assets called Prefabs, which are similar to MovieClips. Unlike Flash, prefabs cannot be nested inside other prefabs without losing their original linkage. This should be accounted for when trying to tweak features across multiple prefabs.

Boccia gameplay

Conclusion

Boccia has now been delivered to the client and should be going live very soon (we’ll let you know when we know!). Overall it’s been a great learning experience for the team, and will hopefully lead to more 3D work in the future, especially as it has recently been announced that Unity will soon export to the Flash player opening up a whole new range of possibilities.

For anyone interested in doing a Unity project here are a few more useful links:

A great introduction to Unity development from the perspective of a Flash Developer:
http://blog.almostlogical.com/2009/11/06/flash-developer-to-unity3d-developer-where-should-i-begin/

Unity based tech-demos, presentations and general eye-candy on their Vimeo channel:
http://vimeo.com/unity3d

A selection of official example projects, tutorials, plugins and extensions:
http://unity3d.com/support/resources/

A comprehensive source of scripts, shaders and tutorial links:
http://www.unifycommunity.com/wiki/index.php?title=Main_Page

The official Q&A community site, easily as important as the Unity manual:
http://answers.unity3d.com


2


Comments

  1. Thanks so much for sharing the details of your work. I look forward to checking out Boccia when it goes live. I love the "How we did it" tag!

    Robert Fauver 6 September 2011, 4:53p.m.

  2. He liked to download this game for the PC? It is possible.
    Thank you.

    Name 24 November 2011, 4:40p.m.

Leave a comment

Personal details