Augmented Reality Game Development - Micheal Lanham - E-Book

Augmented Reality Game Development E-Book

Micheal Lanham

0,0
38,39 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.
Mehr erfahren.
Beschreibung

Create your own augmented reality games from scratch with Unity 5

About This Book

  • Create your own augmented reality game from scratch and join the virtual reality gaming revolution
  • Use the latest Unity 5 VR SDK to create pro-level AR games like Pokemon Go
  • Innovate and explore the latest and most promising trend of AR gaming in the mobile gaming industry

Who This Book Is For

This book is for those who have a basic knowledge of game development techniques, but no previous knowledge of Unity is required. Some basic programming knowledge would be desirable, but the book is an introduction to the topic. The book is also suitable for experienced developers new to GIS or GPS development.

What You Will Learn

  • Build a location-based augmented reality game called Foodie Go
  • Animate a player's avatar on a map
  • Use the mobile device's camera as a game background
  • Implement database persistence with SQLLite4Unity3D to carry inventory items across game sessions
  • Create basic UI elements for the game, inventory, menu, and settings
  • Perform location and content searches against the Google Places API
  • Enhance the game's mood by adding visual shader effects
  • Extend the game by adding multiplayer networking and other enhancements

In Detail

The heyday of location-based augmented reality games is upon us. They have been around for a few years, but the release of Pokemon Go was a gamechanger that catalyzed the market and led to a massive surge in demand. Now is the time for novice and experienced developers alike to turn their good ideas into augmented reality (AR) mobile games and meet this demand!

If you are keen to develop virtual reality games with the latest Unity 5 toolkit, then this is the book for you. The genre of location-based AR games introduces a new platform and technical challenges, but this book will help simplify those challenges and show how to maximize your game audience.

This book will take you on a journey through building a location-based AR game that addresses the core technical concepts: GIS fundamentals, mobile device GPS, mapping, map textures in Unity, mobile device camera, camera textures in Unity, accessing location-based services, and other useful Unity tips. The technical material also discusses what is necessary for further development to create a multiplayer version of the game. At the end, you will be presented with troubleshooting techniques in case you get into trouble and need a little help.

Style and approach

This book shows you how to create every step of the game and gives practical examples.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 396

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Augmented Reality Game Development
Credits
About the Author
About the Reviewer
www.PacktPub.com
Why subscribe?
Customer Feedback
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Getting Started
Real-world adventure games
Location-based
Augmented Reality
Adventure games
Introducing Foody GO
Source code
Getting into mobile development with Unity
Downloading and installing Unity
Setting up for Android development
Installing the Android SDK
Connecting to your Android device
Setting up for iOS development
Getting started with Unity
Creating the game project
Building and deploying the game
Building and deploying to Android
Building and deploying to iOS
Summary
2. Mapping the Player's Location
GIS fundamentals
Mapping
GPS fundamentals
Google Maps
Adding a map
Creating the map tile
Laying the tiles
Understanding the code
Setting up services
Setting up CUDLR
Debugging with CUDLR
Setting up the GPS service
Summary
3. Making the Avatar
Importing standard Unity assets
Adding a character
Switching the camera
Cross-platform input
Fixing the input
GPS location service
Map tile parameters
GPS simulation settings
Character GPS compass controller
Swapping out the character
Summary
4. Spawning the Catch
Creating a new monster service
Understanding distance in mapping
GPS accuracy
Checking for monsters
Projecting coordinates to 3D world space
Adding monsters to the map
Tracking the monsters in the UI
Summary
5. Catching the Prey in AR
Scene management
Introducing the Game Manager
Loading a scene
Updating touch input
Colliders and rigidbody physics
Building the AR Catch scene
Using the camera as our scene backdrop
Adding the catching ball
Throwing the ball
Checking for collisions
Particle effects for feedback
Catching the monster
Summary
6. Storing the Catch
Inventory system
Saving the game state
Setting up services
Reviewing code
Monster CRUD operations
Updating the Catch scene
Creating the Inventory scene
Adding the menu buttons
Bringing the game together
Mobile development woes
Summary
7. Creating the AR World
Getting back to the map
The Singleton
Introducing the Google Places API
Using JSON
Setting up the Google Places API service
Creating the markers
Optimizing the search
Summary
8. Interacting with an AR World
The Places scene
Google Street View as a backdrop
Slideshow with the Google Places API photos
Adding UI interaction for selling
The game mechanics of selling
Updating the database
Connecting the pieces
Summary
9. Finishing the Game
Outstanding development tasks
Missing development skills
Cleaning up assets
Releasing the game
Problems with location-based games
Location-based multiplayer game
Firebase as a multiplayer platform
Other location-based game ideas
The future of the genre
Summary
10. Troubleshooting
Console window
Compiler errors and warnings
Debugging
Remote debugging
Advanced debugging
Logging
CUDLR
Unity Analytics
Issues and solutions by chapter
Summary

Augmented Reality Game Development

Augmented Reality Game Development

Copyright © 2017 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: January 2017

Production reference: 1160117

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham 

B3 2PB, UK.

ISBN 978-1-78712-288-8

www.packtpub.com

Credits

Author

Micheal Lanham

Copy Editor

Safis Editing

Reviewer

Derek Lam

Project Coordinator

Ritika Manoj

Commissioning Editor

Amarabha Banerjee

Proofreader

Safis Editing

Acquisition Editor

Reshma Raman

Indexer

Tejal Daruwale Soni

Content Development Editor

Arun Nadar

Graphics

Jason Monteiro

Technical Editor

Rupali R. Shrawane

Production Coordinator

Shraddha Falebhai

  

About the Author

Micheal Lanham is a solutions architect with petroWEB and currently resides in Calgary, Alberta in Canada. In his current role he develops integrated GIS applications with advanced spatial search capabilities. He has worked as a professional and amateur game developer building desktop and mobile games for over 15 years. In 2007, Micheal was introduced to Unity 3D and has been an avid fan and developer ever since.

To the people I think about every day. My everything, Rhonda and children: Colton, Breann, Mikayla, and Charliegh.

About the Reviewer

Derek Lam is a game designer and Unity Certified Developer who has experience in game design on iOS and Android for over 5 years. In addition, he has a lot of experience in developing augmented reality as well as virtual reality applications. He's currently working in a construction company, producing AR and VR interactive applications, mostly for internal usage.

www.PacktPub.com

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www.packtpub.com/mapt

Get the most in-demand software skills with Mapt. Mapt gives you full access to all Packt books and video courses, as well as industry-leading tools to help you plan your personal development and advance your career.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Customer Feedback

Thank you for purchasing this Packt book. We take our commitment to improving our content and products to meet your needs seriously—that's why your feedback is so valuable. Whatever your feelings about your purchase, please consider leaving a review on this book's Amazon page. Not only will this help us, more importantly it will also help others in the community to make an informed decision about the resources that they invest in to learn.

You can also review for us on a regular basis by joining our reviewers' club. If you're interested in joining, or would like to learn more about the benefits we offer, please contact us: [email protected].

Preface

At the beginning of 2016, most of the world had very little knowledge of augmented reality and location-based games. That, of course, all changed with the release of Pokemon Go later that year. Literally overnight, the genre became entrenched as an upcoming trend in game development. Chances are you have played Pokemon Go and the reason you are reading this book is because of your interest in the genre of AR and location-based games.

In this book we will explore in detail the aspects of creating a location-based AR game just like Pokemon Go. Location-based AR games are expensive and require multiple services for everything from mapping to spawning monsters. However, the game we develop will be done with zero budget using freely available services. While this may not be something you could release commercially, due to some licensing restrictions, it will certainly introduce you to most of the concepts. Along the way, you will also learn how to use a great tool, Unity, and introduce many other concepts in game development.

What this book covers

Chapter 1, Getting Started, introduces the concepts that make up the genre of location-based AR games and our fictional game, Foody Go. This will be followed by a walk-through of downloading all the required software and setting up your mobile development environment with Unity.

Chapter 2, Mapping the Player's Location, starts by introducing the fundamental concepts of GIS, GPS, and mapping. Then shows how those concepts are applied to generating a real-time map and plotting the player’s location in a game.

Chapter 3, Making the Avatar, builds on the previous chapter and transforms our simple location marker into a moving animated character. This allows the player to see their avatar move around the map as they move carrying their mobile device.

Chapter 4, Spawning the Catch, explains that the premise of Foody Go is about catching experimental monsters. In this chapters, we learn how to spawn the monsters around the player on the map.

Chapter 5, Catching the Prey in AR, ups the intensity by introducing integrated AR part of the game by accessing the device's camera, introduces physics for throwing balls, tracking player swiping, using creature reactions, and working with a new game scene.

Chapter 6, Storing the Catch, devoted to developing the player's inventory bag, which will hold all the Foody creatures they catch, and other useful items. Here, we walk the reader through adding persistent storage and adding a simple inventory scene.

Chapter 7, Creating the AR World, adds locations of interest around the player based on a real-time data service.

Chapter 8, Interacting with an AR World, allows the player to interact with the locations of interest. In our simple game, the player will be able to sell their caught monsters.

Chapter 9, Finishing the Game, provides the reader with the information on how to finish the game or better yet write their own location-based AR game. For the purposes of this book, we will only develop the demo Foody Go game.

Chapter 10, Troubleshooting, cover a number of troubleshooting tips and tricks to overcome those development obstacles. As with any software development exercise, problems always arise.

What you need for this book

In order to follow all the exercises in this book you will need, at a minimum, a computer capable of running Unity 5.4+ and an iOS or Android device capable of running Unity games and equipped with a GPS.

More details about Unity system requirements may be found at: https://unity3d.com/unity/system-requirements.

Who this book is for

This book is intended for anyone with an interest in developing their own Pokemon Go, location-based AR game. While this book assumes no prior game development skills or Unity experience, you will need a basic understanding of the C# language or equivalent (C, C++, Java, or JavaScript).

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "The next lines of code read the link and assign it to the to the BeautifulSoup function."

A block of code is set as follows:

#import packages into the project from bs4 import BeautifulSoup from urllib.request import urlopen import pandas as pd

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

<head> <script src="d3.js" charset="utf-8"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>JS Bin</title> </head>

Any command-line input or output is written as follows:

C:\Python34\Scripts> pip install -upgrade pipC:\Python34\Scripts> pip install pandas

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "In order to download new modules, we will go to Files | Settings | Project Name | Project Interpreter."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book-what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of. To send us general feedback, simply e-mail [email protected], and mention the book's title in the subject of your message. If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

Log in or register to our website using your e-mail address and password.Hover the mouse pointer on the SUPPORT tab at the top.Click on Code Downloads & Errata.Enter the name of the book in the Search box.Select the book for which you're looking to download the code files.Choose from the drop-down menu where you purchased this book from.Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

WinRAR / 7-Zip for WindowsZipeg / iZip / UnRarX for Mac7-Zip / PeaZip for Linux

The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Augmented-Reality-Game-Development. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/AugmentedRealityGameDevelopment_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books-maybe a mistake in the text or the code-we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at [email protected] with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at [email protected], and we will do our best to address the problem.[footnote]

Chapter 1. Getting Started

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 isUnderstanding the core elements that make a real-world adventure gameIntroducing the design of our sample game Foody GOInstalling UnitySetting up Unity for mobile developmentCreating the game project

Real-world adventure games

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.

Location-based

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 sceneChapter 3, Making the Avatar, introduces the player character avatar and shows how the mobile's devices and the player's movement will control the avatarChapter 4, Spawning the Catch, is where we start to introduce virtual items onto the map and allow the player to find those itemsChapter 7, Creating the AR World, focuses on populating the virtual world around the player based on real-world locationsChapter 8, Interacting with an AR World, allows the player to interact with those virtual locations

Augmented Reality

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 backgroundChapter 9, Finishing the Game, will discuss some ideas for ways to enhance the AR gameplayChapter 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

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 mapChapter 4, Spawning the Catch, covers many concepts on GIS and mapping and features a short section on object animationChapter 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 effectsChapter 6, Storing the Catch, introduces you to developing a persistent character inventory on a mobile device and more GUI developmentChapter 8, Interacting with an AR World, helps you add additional GUI elements and more particle effects and introduces visual effect shadersChapter 9, Finishing the Game, discusses the possibilities of enhancing the sample game or other ideas for a real-world game

Introducing Foody GO

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 mappingAugmented reality with the cameraRigged and animated 3D avatarAnimated objectsSimple AIParticle effectsGUI menus and controlsPersistent database storageVisual 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.

Source code

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.

Getting into mobile development with Unity

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.

Downloading and installing Unity

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.

Setting up for Android development

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.

Tip

Always install the same architecture version, 64 or 32 bit.

Installing the Android SDK

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.

Note

Always note where you install a development kit like the JDK or SDK.

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, Android/AndroidStudio and Android/AndroidSDK are used:

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 | AndroidSDK. 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.

Connecting to your Android device

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/AndroidSDK folder where we installed the Android SDK to above.Run the following command-line commands:cd platform-tools adb devicesYour 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.

Setting up for iOS development

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.

Getting started with Unity

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.

Creating the game project

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 Assets folder 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 Assets folder.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_SidebySide and 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:Enter FFFFFFFF in the Hex Color field and then close the dialog. Notice how the background of the Game window is now opaque white.

Summary

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.

Chapter 2. Mapping the Player's Location

The core of most real-world games is the location-based map. That integration of the player's real-world position mapped into the virtual world extends the game's virtual elements into the real world, allowing players to explore the world around them with a new perspective and sense of exploration.

In this chapter, we will take our first steps to understanding how to integrate maps into a Unity game. However, before working with Unity, we will cover the basics of GIS and GPS. This will allow us to establish some simple definitions and background for what can be complex topics. After that, we will dive back into Unity and add a location-based map, a basic character, and free look camera to our Foody GO project. Even though we are dealing with advanced concepts, we will keep things simple for now and avoid getting into any code. Of course, more advanced readers with a background in GIS have the options to explore the code at their leisure.

Here is a quick breakdown of what we will cover in this chapter:

GIS terminology and basic fundamentalsGPS terminology and fundamentalsGoogle MapsImporting assetsSetting up servicesDebugging with CUDLR

GIS fundamentals

GIS stands for geographic information system, a system in which geographic data is collected, stored, analyzed, manipulated, and served as maps. Although that definition is still prominent, GIS has come to mean everything from software applications, hardware, tools, science, and services. Google Maps, for example, is the best-known example of a GIS in use today. Yet, in this book, we will also use GIS to mean the science and process of converting geographic data and mapping.

Mapping

Cartographers have been mapping the world around them for thousands of years. Yet only very recently with the development of computers did it become efficient to be used in computers and GIS to create dynamic maps. Unlike traditional hand-drawn paper maps, dynamically rendered maps are composed of layers of spatial data that could describe roads, points of interest, parks, boundaries, landscape, water, and more. As much as the common Google Maps user has little control over what layers are shown, they are there. The following is a figure that shows the typical layers that could comprise a road map:

Source: http://bit.ly/2iri2vr

Google Maps, Bing, and other GIS providers will typically render maps at various zoom levels and then cut those maps into static image tiles. The GIS server then serves those tiles to the user. This works well for performance, but provides few options for customization or styling, aside from adding shapes, lines, or points of interest. This form of tile mapping is often referred to as static mapping. For this book, we will work with the Google Maps API, which provides us with dynamic maps.

Dynamic maps give the presenter or developer options to style and/or symbolize the data as required. For instance, on some maps, you may want to alter parks to be shown as blue instead of green. This is the type of flexibility that dynamic maps provides. When we will add the Google Maps API to our project later in this chapter, we will explore custom style and symbolization options.

Now that we understand the basics of GIS mapping, let's get into understanding some terminologies and concepts. The following is a list of terms we use when describing or making maps:

Map scale: Geographical maps can represent everything from your neighborhood to the whole world. A map scale will often be rendered as text or graphic and provide the user with an understanding of the scope the map covers.Zoom level: This shares an inverse relationship with the map scale. Zoom level starts at 1, which represents a global view of the world, whereas zoom level 17 would represent a map showing your neighborhood. For our game, we will use a small map scale to allow the player to easily identify landmarks around them, which will equate to a zoom level of 17 or 18.Coordinate system: Various coordinate systems have been used across history to geographically locate points of interest. Many people will be familiar with latitude and longitude coordinates, but may not realize there are many different coordinate systems. In fact, the common latitude and longitude that we think is standard also has many variations. Since we will work with Google Maps in this book, we will use WGS 84 coordinates for everything we do. Be aware that if you do try to import data from other GIS, there could be differences that you may need to convert.

The following is a diagram showing WGS 84 major lines of interest:

Source: http://bit.ly/2iOoPNG

Longitude west of the prime meridian is measured as negative. Latitude south of the equator is measured as negative.

Map projection: One of the fundamental problems with mapping is representing our 3D sphere-shaped world onto a 2D service. Early cartographers resolved this issue by projecting a light from a globe onto a cylinder of paper and tracing the outline. The paper was then unrolled and a 2D view of the globe would be seen. We still use a similar method to render a view of our world. Although this 2D view is distorted as you near the poles, it has become the standard for most of our mapping needs. Suffice it to say there are many variations of map projections that are used for a variety of reasons. Other arguably better projection methods have been developed since, such as the Gall-Peters, which better accounts for the distortion at the poles. For us though, we will stick to the Google Maps' standard Google Web Mercator or just Web Mercator. The following is an example of a global map using Web Mercator projection on the left versus the Gall-Peters projection on the right:

Web Mercator projection on the left and Gall-Peters on the right

GPS fundamentals

GPS is an acronym for global positioning system, a network of 24 to 32 satellites that orbit the earth twice every hour. As these satellites orbit, they emit time-encoded geographical signals as a beacon to any GPS device on earth that can see them. A GPS device then uses these signals to triangulate its position anywhere on the planet. The more satellites and signals a device can receive a signal from, the more accurate the location will be. We will get into more details about GPS triangulation and accuracy in Chapter 4, Spawning the Catch.

The following diagram shows a GPS device acquiring a signal from visible satellites on the network:

GPS Device tracking visible satellites

This is a list of terms we may come across when talking about or using GPS on a device:

Datum: It is a term used in GPS to define the coordinate transformation system used to convert those satellite signals into usable coordinates. All GPS devices use WGS 84 as the standard, which is convenient for us since our maps also use WGS 84. A dedicated GPS device will support several different data according to an advanced user's needs.Latitude/longitude: By default, a GPS device will return latitude and longitude coordinates in WGS 84 datum. For us, this makes things easy, as we don't require any additional math conversions to map a device's location.Altitude: This represents the device's height above sea level. Most mobile GPS devices we will be building our game for do not support altitude, currently. Thus, we won't use altitude in the game, but hopefully this will we be supported in the future.Accuracy: This is reported by the device and represents the range of error calculated when determining the location. The more satellites a device acquires signals from, the better the location calculations will be. There is a limit to each device's accuracy and even what is possible on the public GPS network. A modern smartphone will often report at 5-8 meters in accuracy. However, some older smartphones can be as high as 75 meters. We will spend more time discussing GPS accuracy later in the book when we start to allow the player to interact with virtual objects.

Google Maps

As previously mentioned, we will use Google Maps for our map service. For this version of the game, we will use the Google Maps' static map, which means we do not need an API developer key or need to worry about its usage.