Creating the Rollingball scene in Unity

Let's create a directory, Rollingball, to contain our application-specific code and assets. Right-click on the Project pane and choose Folder under Create from the context menu. Rename the new folder Rollingball. Create a subfolder, Rollingball/Scenes, in a similar way.

From the menu bar, select New Scene under File and then select Save Scene as… under File. Save the scene as Rollingball/Scenes/Rollingball.unity.

By default, our newly created scene contains just a camera—that is, the virtual world's camera, not a capture device. We are going to add three more objects in the following way:

  1. From the menu bar, navigate to Game Object | Create Other | Quad. An object called Quad should appear in the Hierarchy pane. Rename Quad to VideoRenderer. This object is going to represent the live video feed.
  2. From the menu bar, navigate to Game Object | Create Other | Directional Light. An object, Directional light, should appear in the Hierarchy pane. It will illuminate the balls and lines in our physics simulation.
  3. From the menu bar, select Create Empty under Game Object. An object called GameObject should appear in the Hierarchy pane. Rename GameObject to QuitOnAndroidBack. Later, it will hold a script component that responds to the standard back button on Android.

Drag Main Camera onto VideoRenderer in order to make the former a child of the latter. A child moves, rotates, and scales up or down when its parent does. The relevance is that we want our camera to maintain a predictable relationship to the live video background.

With the new objects created and Main Camera reparented, Hierarchy should look like what is shown in the following screenshot:

Creating the Rollingball scene in Unity

VideoRenderer and Main Camera will be configured in code based on the properties of the mobile device's video camera. However, let's set some reasonable defaults. Select VideoRenderer in Hierarchy and then, in the Inspector pane, edit its Transform properties to match the following screenshot:

Creating the Rollingball scene in Unity

Similarly, select Main Camera and edit its Transform and Camera properties to match the following screenshot:

Creating the Rollingball scene in Unity

Note that we have configured an orthographic projection, meaning that objects' pixel size is constant, regardless of their distance from the camera. This configuration is appropriate for a 2D game or simulation such as Rollingball.

These four objects are the foundation of our scene. The rest of the project involves attaching custom properties to these objects and using C# scripts to control them and to create new objects around them.