Introducing the game

The game that we are going to look at is a demo sample asset that is free and is an excellent example of a typical game. The game that we'll test will use discrete control mechanics and a first-person perspective, like the games that we have looked at in the past. The technique that we will show you here is how to map/hack into a game's controller so that it can be powered by ML-Agents. Using this technique should allow you to attach ML-Agents to any existing game, although different controllers, such as third-person or top-down, may require a slightly altered approach.

If you consider yourself an experienced Unity user and have your own project that uses an FPS system, then you should go ahead and try to adapt this sample to your own game or example.

You will generally find a lack of good sample game projects for Unity, due to a somewhat questionable technique called asset flipping. Essentially, some developers will take a sample project and quickly skin it as their own game, and then resell it. This practice has primarily been frowned upon in the Unity community, since it generally casts this excellent game engine in a negative light. The quick games, meant only as samples, are often of very poor quality and are unsupported, not to mention that these developers only use the free license, which means that these poorly designed games are also shipped with Made with Unity.  

We want to illustrate how ML-Agents can be incorporated into a working game for testing, debugging, and/or as an AI enhancement. Let's start by importing the base project and setting up the game to run in the editor. Along the way, we may have to tweak a few things in order to get things working, but that is our intent. Open up the Unity editor and follow the exercises in the next section to set up the base game project:

  1. Create a new project called HoDLG (or another name of your preference). Wait for the empty project to load. Again, if you feel qualified, use your own project.
  2. From the menu, select Window | Asset Store.
  1. In the search pane, type ms vehicle system and hit Enter or click on the Search button. We are going to look at a free asset called MS Vehicle System, which has a fun little environment that we can play with. It is often difficult to find free environments such as this (for the reasons mentioned earlier), but, generally, well-made commercial (not free) asset packages will provide good demo environments such as this one. Unity has a number of tutorial environments as well, but they tend to become dated quickly, and they may not always upgrade that easily.
  2. Click on the MS Vehicle System card and wait for the asset page to load, as shown in the following screenshot:
Selecting the asset package to download
  1. Click on the Download button to download the asset, and then click on Import to import the asset into the project. Follow the import dialogues to import all of the assets into the project.
  2. Locate the MainScene scene in the Assets | MSVehicleSystem (FreeVersion) folder, and open it.
  3. Press Play to run the scene in the editor, and use the controls to drive the vehicles around. Notice how you can switch vehicles and camera controls. When you are done testing (playing), stop the scene by pressing Play.
  4. Type canvas in the Hierarchy filter field and just select all of the Canvas objects in the scene, as shown in the following screenshot:
Disabling the Canvas UI in the scene
  1. That will disable the UI in the scene; we won't need it for testing, and in this case, it isn't important. If this were a real game, there might have been more colorful visuals to denote scores, and you could always add those, of course. 
  2. Click on the X beside the filter input to clear it and return the scene to normal.
  3. Play the scene again, and explore several areas. Look for an area that you think may make a suitable goal; remember, don't make it too difficult initially. The following is an example of a spot that might make an interesting goal; see whether you can find the location:

Finding a good place for our goal

Even if you can't find the specific spot, locate an area that is difficult to get to. That way, the agent will have to explore the level extensively in order to find the goal (or goals). In our case, we will drop random goal squares on to the level and encourage the agent to look for those. That way, we can also map out areas that get explored by how often it happens, and then determine how to cover other areas for testing. Before we get to that, we will add ML-Agents, in the next section.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset