This chapter will introduce you to real-world adventure games—what they are, how they work, and what makes them unique. From there, we will introduce the sample real-world game that we will build through the rest of the book. Finally, after the theory, we will do a brisk walk-through on setting up a mobile development environment with Unity.
For those of you who feel that they understand the terminology of real-world adventure or augmented reality games, feel free to jump ahead to the Introducing Foody GO section of this chapter that will discuss the game design and concept of the sample game we will be building throughout the book.
In this chapter, we will cover the following topics:
- Defining what a real-world adventure game is
- Understanding the core elements that make a real-world adventure game
- Introducing the design of our sample game Foody GO
- Installing Unity
- Setting up Unity for mobile development
- Creating the game project
Real-world adventure games are a genre of games that has surged in popularity recently with the release of Pokemon GO. Chances are, at the time of reading this book, you may have certainly heard of, and likely have played, the popular game. Although many think this genre is an overnight sensation, it has in fact been around for several years. Niantic, the developer of Pokemon GO, released Ingress, its first real-world game, in November 2012. The title was, and is, popular, but has only attracted a niche following of gamers, which was likely more the result of the game's complex theme rather than being specific to the genre.
Now, many can suggest that the primary catalyst that launched Pokemon GO into a gaming sensation is the Pokemon franchise combined with a new augmented reality gaming platform. Certainly, without its integral real-world interaction, Pokemon GO would have been just another popular mobile game.
So, what are the elements that make a real-world adventure or location-based augmented reality game unique?
- Location-based: Players have the ability to interact with virtual objects or places around them using a map. As the player physically moves in the real world, their device's GPS will update the player's location in the game, thus allowing the player to move to virtual locations and search for or interact with virtual objects or things. We will discover how to integrate the device's GPS and display a map in Chapter 2,Mapping the Player's Location.
- Augmented Reality (AR): A player interacts with the real world through their device's camera. This allows them to view and interact with the virtual place or thing against the backdrop of the real world around them. Using the device's camera as a game background in order to enhance the user experience will be introduced in Chapter 5, Catching the Prey in AR.
- Adventure game: Players typically assume the role of an avatar driven by a mission of exploration and puzzle solving in order to ultimately reach some story-driven goal. Of course, other notable games in the real-world genre may loosely fit that definition. For the purposes of this book, we will adhere to that loose definition of adventure game. The Introducing Foody GO section in this chapter will cover the game design and concept of the real-world adventure we will be building through the rest of the book.
Of course, there are many other elements that will be needed to create a successful game, but essentially, location-based and augmented reality are the elements that identify the real-world adventure genre. Astute readers may notice that massively multiplayer network gameplay or MMO was omitted. Although MMO gameplay may be essential to certain game designs, it is not a requirement of this genre.
Tracking a player's location in the real world and then overlaying that into the game's virtual world creates a unique level of immersion for players. In fact, in many real-world adventure games, warning messages are presented to players before they start playing. There are many stories of players becoming so immersed that they have hurt themselves due to an avoidable accident while playing a real-world game.
Mapping the real world on top of the game's virtual world provides new challenges to traditional mobile gaming. Developing a map interface and populating it with virtual items require some advanced GIS skills. Many developers will be new or relatively inexperienced in the concepts of GPS and GIS or rendering a map in Unity. Since mapping is a core concept to the real-world genre, it will be the basis for much of the sample game we will be building. We will spend several chapters related to the topic of maps. The following is a list of chapters that will touch on mapping and location:
- Chapter 2, Mapping the Player's Location, starts with a basic discussion of GPS and GIS and then show you how to load a map texture into a 3D Unity scene
- Chapter 3, Making the Avatar, introduces the player character avatar and shows how the mobile's devices and the player's movement will control the avatar
- Chapter 4, Spawning the Catch, is where we start to introduce virtual items onto the map and allow the player to find those items
- Chapter 7, Creating the AR World, focuses on populating the virtual world around the player based on real-world locations
- Chapter 8, Interacting with an AR World, allows the player to interact with those virtual locations
AR has been around since 1990. The term typically covers a broad range of technologies from virtual surgical devices, Microsoft HoloLens, and mobile apps such as Snapchat. AR technologies have been slow to become mainstream in gaming until just very recently. With the advance of new technologies and the real-world adventure genre being major contributors to increasing popularity of AR in gaming.
As mentioned, AR covers a broad range of technologies or devices that provide an overlaid virtual environment to the user. However, on a mobile device, the AR experience is often a result of rendering a virtual environment over a backdrop of the device's camera. In some cases, the AR game or application will have sophisticated image processing algorithms that identity features. Those identified features may then be annotated virtually with other graphics or game options. Pokemon GO, for instance, limits the use of AR to just the camera background, whereas Snapchat provides a dynamic AR experience to the user through the use of image processing. Yet, both the game and application benefit by providing the user with a more enjoyable experience through AR.
For the purpose of the real-world adventure genre and this book, we will take a basic approach to provide the user with a basic AR experience. That means, we will look at integrating the mobile device's camera as a game backdrop. The gaming experience will be familiar to other popular games in the genre. Even with this basic approach to AR, we will still cover a number of other details and tips in the course of a few chapters. The following is a short description of the AR elements that we will work on in the subsequent chapters:
- Chapter 5, Catching the Prey in AR, will introduce using the mobile device's camera as our game's background
- Chapter 9, Finishing the Game, will discuss some ideas for ways to enhance the AR gameplay
- Chapter 10, Troubleshooting, will help you just in case things don't work as expected; this chapter will identify potential issues and provide tips to resolve them
Adventure games are typically characterized by a quest-driven story where players must explore and solve puzzles in order to complete the game, whereas the current real-world adventure games are more about exploration than puzzle solving and completing a quest. If anything, the current batch of real-world games are more like a Role-Playing Game (RPG) than a classic adventure game. In the future, we may certainly see more true classic adventure games or possibly other real-world mixes, such as real-time strategy, shooters, simulation, educational, sports, and puzzle.
In order to demonstrate how all these new concepts come together, we will be building a sample game throughout the book. This game will loosely follow an adventure style not unlike other popular titles in the real-world genre. In this game, we will be adding many common game elements, such as an avatar, character inventory, particle effects, and more in the course of several chapters; the following is a short introduction to those chapters:
- Chapter 3, Making the Avatar, helps you to add a 3D rigged and animated character to our map
- Chapter 4, Spawning the Catch, covers many concepts on GIS and mapping and features a short section on object animation
- Chapter 5, Catching the Prey in AR, introduces AR and many other gaming concepts, such as texturing, rigid body physics, player input, AI, GUI menus, and particle effects
- Chapter 6, Storing the Catch, introduces you to developing a persistent character inventory on a mobile device and more GUI development
- Chapter 8, Interacting with an AR World, helps you add additional GUI elements and more particle effects and introduces visual effect shaders
- Chapter 9, Finishing the Game, discusses the possibilities of enhancing the sample game or other ideas for a real-world game
Certainly, the best way to learn any new or advanced concepts is by example. Foody GO will be our example real-world adventure game that we will be building throughout the book. The game will follow a food theme where the player will search for and catch experimental cooking monsters. Once caught, the player must take their monsters to local restaurants in order to sell them for items, power and prestige.
Of course, our sample game will focus on the location-based augmented reality elements, but we will introduce several other technical features, as follows:
- Player mapping
- Augmented reality with the camera
- Rigged and animated 3D avatar
- Animated objects
- Simple AI
- Particle effects
- GUI menus and controls
- Persistent database storage
- Visual shader effects
We won't get into extensive detail on any of the preceding features, as most of these items could cover a book by itself. However, it will be helpful to understand how each of these elements comes together to make a real-world adventure game.
All of the books source code can be downloaded from SITE. The source code will be broken down chapter by chapter and provided as a progressive project. For each chapter, the starting and ending project's states will be provided. This will allow the more advanced reader to jump ahead in the book. Novice readers are encouraged that you follow all the examples in the book, as later chapters will be more advanced in content.
Now, with all the background set and our course laid out, let's get started by introducing mobile development with Unity. More advanced readers who have developed Unity games on Android or iOS may want to skip ahead to Chapter 2, Mapping the Player's Location.
This installation guide is intended to be cross-platform compatible and should work on Windows, Linux, or Mac. For the sake of brevity, only screenshots for the Windows platform will be shown.
Even if you have installed Unity before, but have not done mobile development, make sure that you follow this section closely. There are a couple of important steps you would not want to miss.
Perform the following steps to install Unity:
- Open any browser and go to https://unity3d.com/.
- Browse through the site and download the Unity installer for the latest stable release. If you have never downloaded Unity before, you will need to create a new account.
- Run the Unity installer, click on Next to accept the license agreement and click on Next again.
On the architecture dialog, shown in the following screenshot, make sure that you select 64 bit:
On the select components dialog, make sure that you choose your preferred mobile platform, Android or iOS. Many users will just select all features and install. However, it is better to be selective and install only what you need. Installing all Unity features will require about 14 GB of space, and this can quickly add up if you have installed more than one version.
In the following example screenshot, we have selected both Android and iOS. Ensure that you only select the platform you need:
Choose only the components you need
- Select the default installation path for Unity and then click on Next to install.
Even with the limited number of components, the installation will still take several minutes, so grab a coffee and wait until it completes.
If you are using an Android device to test the game, use this section to get ready. Developers who already have experience with Android can briefly review this section or jump ahead to the Getting Started with Unity section in this chapter.
Follow the subsequent steps to install the Android SDK on your development computer. Even if you already have the SDK installed, please review these steps to ensure that you have the right path and components set:
- If you have not already done so, download and install the Java Development Kit (JDK) from http://www.oracle.com/technetwork/java/javase/downloads/index.html.
- Download the latest version of Android Studio from https://developer.android.com/studio/index.html.
- After Android Studio has finished downloading, follow the instructions on https://developer.android.com/studio/index.html to start installation.
As you install Android Studio, make sure that you also install the Android SDK, as follows:
Install the Android SDK component
For the installation location, change the path to something that is easy for you to remember and locate. In the example screenshot,
Select an installation location that will be easy to find later on
After the installation completes, open Android Studio. Open the Android SDK Manager by selecting menu item Tools | Android | Android SDK. In the following example screenshot, only Android 5, API Level 21 is selected because it matches the device:
Set the Android SDK location and select API level that matches your device
- On the Android SDK panel, set the location path to the same as you used in step 5. Then, select to install Android API level that matches your Android device and click on Apply. Locate the Android version of your phone from Settings | About phone | Android version. This API installation may take several minutes, so this will be a good time for another coffee or the beverage of choice.
- After the API installation completes, close Android Studio.
For best results when following the examples in this book, you will need to connect a physical device to your computer for testing. It is possible to emulate a GPS and camera in an Android emulator, but that is beyond the scope of this book. Follow these steps to get your device connected:
- Install the driver for your Android device by following this guide: https://developer.android.com/studio/run/oem-usb.html#InstallingDriver.
Enable USB debugging on your Android device:
- On Android 4.2 and higher: The Developer options screen is hidden by default. To make it visible, go to Settings | About phone and tap on Build number seven times. After the seventh tap, you will see a message informing you that the developer options are enabled. Return to the previous screen and select Developer options at the bottom to turn on USB debugging.
- On older versions of Android, go to Settings | Applications | Development to turn on USB debugging.
- Connect your device to the computer. On the device you will be prompted to allow USB debugging. Choose Ok and wait for a few seconds to make sure that the driver connects.
- Open a command or console window on your computer and navigate to the
Android/AndroidSDKfolder where we installed the Android SDK to above.
Run the following command-line commands:
cd platform-tools adb devices
Your device should show up in the list. If for some reason you do not see your device in the list, consult Chapter 10, Troubleshooting. The following console window shows the commands run and sample output:
That completes the bulk of setting up an Android device. We still have a couple more settings to make in Unity, but we will cover that in the next section on project setup.
In order to keep the content of this book focused and the development platform independent, we will not provide a step-by-step guide here. However, there is an excellent guide for iOS setup on the Unity site at https://unity3d.com/learn/tutorials/topics/mobile-touch/building-your-unity-game-ios-device-testing.
After you complete your iOS setup, return to the book, and we will begin building the example game project.
Unity is a great platform to start learning game development or even shipping a commercial game. It is the choice of game engine for many of the popular games in the Android or iOS app stores. So, what makes Unity such a great platform to develop games on? The following is a short list of things that make Unity such a compelling platform to develop games on:
- It is free to get started: There is a ton of free assets or code you can use to build games. We will look at a number of free assets in this book.
- Incredibly easy to use: You could likely build a complete game in Unity without writing even one line of code. Fortunately, you will learn some scripting and how to write code in this book.
- Entirely cross platform: With Unity, you can develop on or for any environment that suits you. Of course, certain platforms, such as mobile, still have limitations and we will cover that as well.
- Outstanding community: Unity has a hardcore base of developers who are eager to share experiences and help others. We will be sure to showcase many of the great community resources.
- Asset Store: The Unity Asset Store can be an invaluable tool to build your first game or even your seventh commercial title. We will show you the deals and what to avoid.
Let's get started by creating our sample game project Foody GO; we will also take this opportunity to build and deploy this starting project to your mobile device:
Launch Unity and start a new project named
FoodyGO. Make sure that 3D is enabled and disable Unity analytics. Of course, you will want to save your project in an easy-to-find folder, such as Games, just as shown in the following sample screenshot:
- Click on the Create project button and wait for Unity to open.
In the Hierarchy window (top-left corner), you will see a scene named Untitled. Beneath that, there will be the Main Camera and Directional Light attached. Here is the screenshot of what you will see:
- First thing you will want to do is rename the scene and save it. So, go to File | Save Scene As...
- A save dialog will open, allowing you to choose where to save the scene. Just choose the default
Assetsfolder and name your scene
Splash. Then, click on Save.
- The title of the scene should now read Splash. Notice that there is also a new Splash scene object in the project
- Now let's adjust the Unity editor layout to match how our mobile game will run. From the menu, select Window | Layouts | Tall. Then, undock the Game tab from the main window by selecting and clicking the mouse while dragging the tab over. Then, resize the window so both the scene and game windows are roughly of the same width.
- Save the layout by opening the menu to Window | Layouts | Save Layout. Name your layout
Tall_SidebySideand click on Save. This will allow you to quickly return to this layout later.
Select the Main Camera by double-clicking on it, in either the Hierarchy window or Scene window. Notice how the Scene window will focus on the Main Camera object, and the Inspector window will display all the properties. This is what the Unity editor window should look like now:
Editor layout for mobile development
Before we go further, let's take a look at each of the main windows we will be working with in Unity:
- Scene window: This window will allow you to view and interact with the game objects in the scene.
- Game window: This is the players' view of the scene rendered by the main camera.
- Hierarchy window: This shows a tree view of the game objects in the scene or scenes. In most cases, you will select or add items to the scene in this window.
- Project window: It provides a view of and a quick way to access the assets in your project. Not much is in our project now, but we will quickly add some new assets in the coming chapters.
- Inspector window: This view allows you to inspect and alter settings on game objects.
- Click on the Play button located at the top middle of Unity editor. The game will start playing, but nothing will happen because we only have a camera and a light. So let's add a simple Splash screen.
- In the Hierarchy window, select the scene. From the menu, select Game Object | UI | Panel to add a Canvas and Panel to the scene.
Double-click on the Panel object in the Hierarchy window. This will focus the Scene window on the panel. In the Scene window, switch the view to 2D by clicking the button at the top of the window. This is what you should see now:
Editor window with UI focused on in Scene window
- The panel in the scene window is a 2D UI element that allows us to render text or other content to the player. By default, the panel centers itself to the main view of the camera when it is added to the scene. This is why we see the semitransparent panel cover the entire Game window. Since we don't want a transparent background to the splash screen, let's change the color.
Select the Panel in the Hierarchy window. Then, click on the white box beside the Color property in the Inspector window to open the Color settings. You will see the following dialog:
FFFFFFFFin the Hex Color field and then close the dialog. Notice how the background of the Game window is now opaque white.
From the menu, select Game Object | UI | Text. In the Inspector window, set the properties of the Text to match the screen extract, as follows:
- Run the game by clicking on the Play button. Not much happens, but we now have a splash screen for our game. Don't worry, later in the book, we will add some pizazz to this screen. For now though, let's get this game deployed to your device.
Now that we have the foundations of our game and a simple splash screen let's deploy it to your device. Nothing confirms your progress as a game developer other than seeing your game run outside the Unity editor. Follow the section that is specific to your device to complete the build and deployment.
As long as you have followed the steps for installation in the previous sections of this chapter, deploying your game to Android should be simple. If you do encounter any deployment issues, refer to Chapter 10, Troubleshooting. Follow the next steps to build and deploy to your Android device:
- From the menu, select Edit | Preferences. This will open the preferences dialog.
Select the External Tools tab. Change or set the location of your
Android SDK Pathand
Java JDK Pathto the installation paths we made a note of when installing. Close the dialog when you are finished. The subsequent sample screenshot shows where you need to enter those paths:
Select Edit | Project Settings | Player from the menu. Select the Android Settings tab and then click on Other Settings at the bottom of the panel. Set the Bundle Identifier to
com.packt.FoodyGOas shown in the following screenshot:
- Make sure that your Android device is connected by the USB. Refer to the Connecting to your Android Device section earlier in this chapter if you are unsure.
Open the Build Settings by selecting from the menu File | Build Settings. On the Build Settings dialog, click on the Add Open Scenes button to add the Splash scene. Ensure that you select the Android build from the list of build types. When you are all set and ready, click on the Build and Run button. This is how the Build Settings dialog should look like:
- A file save dialog will open the project's root folder. Create a folder called
Buildwhile you still have the dialog box opened. Open the new Build folder and save your build as
com.packt.FoodyGO. The name should match the name we used for the build identifier earlier. Then, click on Save to start the build.
- Since this is the first build of the project, Unity will reimport all the project assets and other modules, which may take a few minutes. Subsequent builds should take less time, but if you change platform outputs, everything will need to be reimported.
- After the build completes, open your device. You will likely see the Unity screen loading and then the splash screen. Congratulations, you have deployed the game to your device.
Assuming you followed the previous section, Setting up for iOS development, you should be able to already build and deploy the game to your device. Just follow the build and deployment steps again in that page to deploy the game to your device. Download the sample project for the chapter and deploy that to your iOS device.
For this chapter, we started out by introducing what the genre of real-world adventure games is and why it has become so popular. We then went into more detail on the major components that comprise the genre and how we will be covering each component in the book. After that, we introduced the sample game Foody GO that we will be building as a sample real-world adventure game. Then, we dove headfirst into installing Unity and the required dependencies for building, deploying, and testing it on your mobile device. Finally, we created the Foody GO game project and added a simple splash screen.
In the next chapter, we will continue building on the Foody GO game project and start to add mapping. However, before we add maps to our game, we will cover some basics on GPS and GIS.