Unity Summer of Code – Detonator

I wrote a proposal for a parametric explosion system for the Unity Summer of Code… and it was one of four accepted out of over a hundred! I’m excited to be working with Unity engineer Jonas Echterhoff as my mentor – and I’ll definitely need his help. Here’s the announcement: http://blogs.unity3d.com/2009/07/22/unity-summer-of-code-takes-off/

And here’s the proposal:


Great explosions can make a game. Bad explosions can ruin a game. As important as they are, they are difficult to do well because they are composed of art and complex behavior that’s not easily consolidated into a single object. Explosions also have a high degree of randomness, yet within a domain that is not easily described and is often violated.

That said, Unity developers of all types could make great use of a system that allows for efficient creation and iteration of explosion effects.

For artists, the system will provide a means to harness and iterate on complex behavior that is normally hidden behind coding barriers. Artists can think in terms of “size” and “intensity” of the explosion as a whole, while also drilling down to tweak details. Detonator is more than just a collection of particle emitters.

For programmers, creating an explosion with great visual quality will no longer hinge on finding pre-existing particle libraries or an artist friend. Detonator will provide solid results from the start. It will also allow easier binding of game logic to explosion parameters by providing meta-parameters that combine several emitters, models, lights, into a single “Intensity” or “Duration” value.


  1. Allow non FX-specialists to easily experiment with different looks for their explosions.
  2. Tie explosion parameters to game events and parameters. ie – have one explosion for damage, one for destruction, all calling the same script but based on remaining hitpoints of the gameobject
  3. Tie explosion physics to global parameters such as gravity and wind so they can be tweaked and altered at run time in one place.
  4. Allow the creation of named explosion presets (prefabs) – this will enable code to spawn type of explosion based on incoming weapon
  5. Create a method where the explosion render complexity scales according to frame rate, total particle count, priority, etc. and provide global and per prefab complexity values for easily tying to code.
  6. Let the developer decompose the explosion into its component pieces if he wants to use the system as simply a baseline for further art.

As part of the process of building Detonator, we’ll define what an explosion is and create taxonomy for all of its components. The system will consist of 4 layers.

  1. Layer 0 – The raw gameobjects and scripts
  2. Layer 1 – Per component parameters
  3. Layer 2 – Per explosion parameters
  4. Layer 3 – Detonator System wide parameters

Example Layer 0:

  1. Particle Emitters
  2. Scripts
  3. Lights
  4. Models
  5. Animations

Example Layer 1:

  1. Flash – A screen space flash
    1. Color
    2. Duration
    3. Size
  2. Screen Shake
    1. Intensity
    2. Period
    3. Seed
  3. Sparks – Ignited, small debris that shoots straight out
    1. Number
    2. Color
    3. Size
    4. Length
  4. Debris – Larger chunks that can trail a particle effect
    1. Number
    2. Model(s)
    3. Size
    4. Color
    5. Trailing Particle
  5. Shockwave – A scaling model (sphere, cylinder)
    1. Size
    2. Duration
    3. Color
  6. Light – A point light that animates with the duration of the explosion
    1. Intensity
    2. Radius
    3. Color
  7. Fire – The main body of the explosion
    1. Texture
    2. Color
    3. Size
    4. Duration
    5. Pieces
  8. Smoke
    1. Texture
    2. Color
    3. Size

Example Layer 2:

  1. Size
  2. Intensity
  3. Smokiness
  4. Gravity
  5. Chunkiness
  6. Complexity

Example Layer 3:

  1. Gravity
  2. Wind
  3. Complexity

So, follow along. With any luck Detonator will turn into something the community will make good use of.

Digging into Unity3D – Part 2

So yesterday I spent several hours with Unity and discovered some cool stuff.

First I put together something like a Hello World app… certainly not a game, but what I’d consider the bare minimum that’s still “something”. I wouldn’t quite call this a tutorial since I only started myself, but if you are at Step Zero with Unity you may find it useful in understanding the basics.  At the end, we’ll have a terrain, a sky, and a controllable player. There will be a camera tied to the capsule in first person. Then once we’ve done that, we’ll switch it to third person. Most of these instructions were found in the comments of the scripts that come with Unity… which was the first revelation that I had about how to learn. Online tutorials are good, but the example stuff is commented very well and explains a lot.

So, here’s what I did.

  1. Make a new project and use the standard Unity assets.
  2. Let’s rearrange our windows a bit so we can see the game and scene views at the same time. Drag the Scene tab down to the bottom of the Scene viewport. It should expand to fill the bottom half. Release it and you’ll have the Game view on top and the Scene view on the bottom. Very handy.
  3. Choose Menu->Terrain->Create Terrain
  4. Choose Menu->GameObject->Create Other->Directional Light
  5. With the directional light selected, hit “E” to enter rotate mode.
  6. Grab the red circle on the rotation maniuplator and drag it until it’s about 45 degrees down (+45 degrees if you’re looking at the transform in the Inspector to the right.) Notice the terrain lighting up.
  7. Choose Main Camera in the Hierarchy Panel
  8. Choose Menu->Component->Rendering->Skybox – This creates a spot for us to drop a piece of Skybox art onto the camera. Once we do, it knows exactly how to act.
  9. In the Project Panel, there are some basic starter assets. Get to Standard Assets->Skyboxes and drag Blue Sky over to Inspector panel with the Main Camera still selected. Drop it on the spot that says Custom Skybox.  The sky should show up in the Game view, but not the Scene view.
  10. Now we’ve got land and a sky. Let’s add a player. Choose Menu->GameObject->Create Other->Capsule.
  11. Click in the Scene view and then make sure Capsule is still selected. Hit “F” to focus on the capsule. Pretty cool how it smoothly zooms for you so you can get some idea of relational space.
  12. The capsule is half in the terrain, so let’s raise it up. Hit “W” to go into Move mode and drag the Green arrow up a bit. Hit F again to refocus.
  13. Now here’s interesting part. In Project, open up the Camera Scripts folder. Double click on MouseLook. Notice in the comments that there’s instructions on how to make the Capsule into an FPS style character. They read:
?View Code CSHARP
using UnityEngine;
using System.Collections;
/// MouseLook rotates the transform based on the mouse delta.
/// Minimum and Maximum values can be used to constrain the possible rotation
/// To make an FPS style character:
/// - Create a capsule.
/// - Add a rigid body to the capsule
/// - Add the MouseLook script to the capsule.
///   -> Set the mouse look to use LookX. (You want to only turn character but not tilt it)
/// - Add FPSWalker script to the capsule
/// - Create a camera. Make the camera a child of the capsule. Reset it's transform.
/// - Add a MouseLook script to the camera.
///   -> Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.)
[AddComponentMenu("Camera-Control/Mouse Look")]
public class MouseLook : MonoBehaviour {
	public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
	public RotationAxes axes = RotationAxes.MouseXAndY;
	public float sensitivityX = 15F;
	public float sensitivityY = 15F;
	public float minimumX = -360F;
	public float maximumX = 360F;
	public float minimumY = -60F;
	public float maximumY = 60F;
	float rotationX = 0F;
	float rotationY = 0F;
	Quaternion originalRotation;
	void Update ()
		if (axes == RotationAxes.MouseXAndY)
			// Read the mouse input axis
			rotationX += Input.GetAxis("Mouse X") * sensitivityX;
			rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
			rotationX = ClampAngle (rotationX, minimumX, maximumX);
			rotationY = ClampAngle (rotationY, minimumY, maximumY);
			Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
			Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
			transform.localRotation = originalRotation * xQuaternion * yQuaternion;
		else if (axes == RotationAxes.MouseX)
			rotationX += Input.GetAxis("Mouse X") * sensitivityX;
			rotationX = ClampAngle (rotationX, minimumX, maximumX);
			Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
			transform.localRotation = originalRotation * xQuaternion;
			rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
			rotationY = ClampAngle (rotationY, minimumY, maximumY);
			Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
			transform.localRotation = originalRotation * yQuaternion;
	void Start ()
		// Make the rigid body not change rotation
		if (rigidbody)
			rigidbody.freezeRotation = true;
		originalRotation = transform.localRotation;
	public static float ClampAngle (float angle, float min, float max)
		if (angle < -360F) 			angle += 360F; 		if (angle > 360F)
			angle -= 360F;
		return Mathf.Clamp (angle, min, max);

Now, there are a few little things in those comments that might be confusing to an absolute beginner.

///To make an FPS style character:
/// - Create a capsule.

We’re good here.

/// - Add a rigid body to the capsule
With the Capsule selected, choose Menu->Component->Rigid Body

/// - Add the MouseLook script to the capsule.
Drag the MouseLook script from the Project panel onto the Capsule’s empty area in the Inspector

/// -> Set the mouse look to use LookX. (You want to only turn character but not tilt it)
Set the “Axes” to “MouseX”

/// - Add FPSWalker script to the capsule
Drag this to the Capsule’s Inspector from Project panel->Standard Assets->Scripts

Once you do all this stuff, hit the play button up top. If you’ve done it right, the the ASWD keys will move your capsule around and your mouse will turn it in the Scene view. Sweet, right?

The next steps actually hook a camera up to the Capsule. Unity relies on object hierarchies much like 3D modeling software does. So if I were in 3DSMax and I wanted to have a camera attached to this capsule, I’d parent the camera to the capsule… and that’s exactly what we do here.

So, in the Hierarchy panel, drag the Main Camera onto the Capsule. Now again, just like in 3D software, the transform of the camera is now relative to the capsule instead of the world. So let’s put the Camera at 0,0,0 in the Capsule’s space by selecting the camera, clicking the little Gear icon next to its Transform in the Inspector panel, and choosing “Reset”. Notice that X,Y,Z all go back to 0? You may also notice the Game view updating a bit. Hard to tell since the Terrain is completely flat. In fact, let’s paint some test terrain real quick to have a frame of reference.

Choose the Terrain in the Hierarchy panel. Notice in the inspector there is a series of icons for painting terrain? Just get in there and mess it up a bit. We just need a few hills and valleys to be able to tell what’s going on. Click in the Scene view and either mousewheel to zoom out or hit F to expand the view. Then click the Raise Terrain button on the Terrain inspector and paint some hills. Try not to paint exactly on the Capsule since it will put the Capsule below the Terrain. Just do some stuff off in the distance so we can tell what’s going on.

Now let’s run the game and see what we see. Nice! If you click in the game view, you’ll see that the mouse now turns the camera and ASWD moves, all in first person.

The last step is to make it so the camera can look up and down. Going back to the script’s comments,

/// - Add a MouseLook script to the camera.
/// -> Set the mouse look to use LookY. (You want the camera to tilt up and down like a head. The character already turns.)

So let’s do just that. With the Main Camera selected, drag that MouseLook script over and set the Axes to MouseY. Hey, we can look up and down. Nice.

Ok so lastly, you need to be introduced as early as possible to one of the big gotchas in Unity 2.5. Notice that the game is still running? Click the Play button while looking at the Inspector panel with the Main Camera selected.

Hey! Our MouseLook disappeared! WTF? Yes, ANYTHING you do while the game is running is considered an “experiment” and is NOT saved. You could work for hours and lose all of it. So get in the habit VERY early of knowing when you are and are not playing the game. Got it? :)

Digging into Unity3D – A Flex Developer/Technical Artist’s Perspective

Yeah that title is kinda weird, right? Well that’s my background. I wrote Mrs. Riley’s PageBuilder with Flex and was a Technical Artist for Vicarious Visions for over 3 years, working with a lot of awesome 3D technologies including VV’s Alchemy and 3DSMax while making games there. I’ve always wanted to work on my own game – as far back as college. The problem has always been finding a toolset that has the capabilities in 3D to take advantage of my art skills while isolating me from the real nitty gritty engine coding duties that are far too involved for me to tackle alone.

A few years back I came across the Unity engine when it was Mac only. I was pretty interested, but it’s only recently that I’ve started to really have a go at it and so far, I’m impressed. Unity is very visual. A scene has a hierarchy of objects that all have a visual representation in the world – some more as proxies to code, some as real 3d assets. But that organizational difference is really important for my way of thinking and learning. I suspect that there are a lot of other folks that feel the same way because it’s really gained traction over the past year. And of course it doesn’t hurt that they provide a version for developing iPhone games.

So, my first few hours have been spent going over tutorials. Unity provides a few projects with nicely written PDF tutorials here. So far I’ve spent time with only the 2D Platform Tutorial. It’s just a simple character on a couple platforms along with controller logic, physics, particles, a skybox, and some UI. Ok so, maybe not that simple. In fact, what I really want to find is a dead simple hello world type tutorial. I’d like to create a terrain, import a model from Max, hook up some kind of control via the keyboard, and move the model around the world. I don’t even care if the camera follows around this point. I’ve looked for a few minutes and haven’t seen anything so far.

So that’s the next post. Right now though I haven’t been this excited by a piece of software since I drove up to Toronto with my Dad in 1996 to get a copy of 3DSMax 1.0 Educational. (it was $995 Canadian) That was the best investment of my career and I have a feeling that Unity will be another great one.

What is Variance Theory?

Variance Theory is my personal portfolio and blog site. The term Variance Theory refers to some ideas on game design that I’ve been meaning to congeal into written form from notes over the years. BUT – we just had a baby! On 6/30! So I’ll be working on this inbetween coddling and pacing at the wee hours of the night.