Reader small image

You're reading from  Creating E-Learning Games with Unity

Product typeBook
Published inMar 2014
Reading LevelIntermediate
Publisher
ISBN-139781849693424
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
David Horachek
David Horachek
author image
David Horachek

David Horachek is a video game software developer with over 13 years of experience in programming arcade, home console, and portable games. He has programmed game projects published by Midway Games, EA, Ubisoft, SEGA, and others. He develops games under the Arbelos Interactive label.
Read more about David Horachek

Right arrow

Chapter 7. Mission Two – Testing a Player's Learning

In this chapter, we will program the second mission for our e-learning game. The objective of this level will be to test the learning that occurred in the first flag-collecting level. The theme of the level will be a race against two other NPCs through a park, where the player will have to answer trivia questions from NPCs placed randomly along the path. The player will have to achieve 100 percent accuracy and be placed first in the race in order to advance to level three.

In this chapter, we will cover the following topics:

  • Exploring the structure of mission two

  • Defining the framework for mission two

  • Adding a mission to the missionMgr script

  • Extending the GameCam script

  • Modifying the terrain

  • Adding NpcRacers to the mission

  • Creating the start and finish line flags

  • Creating the LevelStart and LevelFinished pop ups

  • Creating the setupLevel2 Prefab

  • Creating the raceStartup Prefab

  • Implementing the LevelLogicObj GameObject

Exploring the structure of mission two


The choice of a quiz race for mission two's gameplay was made to fill a number of e-learning game design requirements.

Recall that learning does not occur in a vacuum. Without testing for player comprehension, we cannot assess quantitatively how much learning has occurred, so a form of player interaction is necessary; the NPCs presenting the quiz cards fills this role. This is the source of challenge in the game.

The other racers chasing the player through the course add a level of pressure on the player. This is the source of intensity or pressure in the game.

Recall that testing and pressure are the two parameters necessary to create a learning environment that encourages cognitive flow. Having constructed our level according to this model, we can adjust the difficulty of the quiz questions and the speed of the other players to influence the fun and learning effectiveness of the game.

Defining the framework for mission two


As with mission one, we will organize our game objects into hierarchies as shown in the following screenshot:

The _global GameObject hierarchy will contain objects that persist for the entire lifespan of the game, and we will develop other hierarchies for objects that persist during a specific level.

To begin, let's create a new scene file for the level. Name the scene TESTBED2. Inside this scene, let's add two empty game objects at the root level, placed at (0,0,0) as with the first level. Name them _global and _level2.

  1. Under _global, add the layer, camera, and GameObject. Recall that these objects and their scripts persist across all levels.

  2. Under _level2, we will add level 2's specific GameObjects. As we create them throughout this chapter, we will add them to the hierarchy formed with the object named _level2 as the root.

    The following objects will be placed in this hierarchy:

    • _splineDataA and _splineDataB: These are two collections of control points...

Adding a mission to the missionMgr script


Recall the missionMgr script attached to the GameObject (a child of _global). This is the class that manages tracking objectives in the game. In order to create a new mission for level two, let's perform the following steps:

  1. Select the missionMgr script, and set the size of the mission's component to 1, telling the system we will have one mission in this level.

  2. Set the mission to activated, visible, and MS_ACQUIRED so that the level starting with this mission is ready to be processed from the start.

  3. Set the display name to win the race and the description to achieve 100% accuracy and first place in the race.

  4. Set the token component size to 0. Another script will fill these dynamically, but eventually it will be filled with the randomly chosen flags from Chapter 1, Introduction to E-Learning and the Three Cs of 3D Games.

  5. Set the points to 2500 and the reward object to null.

This is a sufficient setup for the mission on initialization.

Extending the GameCam script


The GameCam script's logic needs to be extended for this mission to support the ability to look up in the sky and back down at the player. To do this, a couple of simple methods need to be added to adjust the lookat GameObject.

A public method named LookUp will find the object named lookUpTarget and swap the lookObj in the script with the following code snippet:

public void LookUp()
{
   GameObject go = GameObject.Find("lookupTarget");
   if (go)
      lookObj = go;
}

Note

lookUpTarget is an empty GameObject parented to the player, placed 100 units above him or her in Y—a simple and effective way of looking up above the player.

A second method, named LookPlayer, will restore the lookObj back to the player object. This resets the camera back to third person functionality as shown in the following code snippet:

public void LookPlayer()
{
  if (trackObj)
    lookObj = trackObj;
}

Modifying the terrain


Since the theme of this level is a race, we need to create a nice winding path through the level. Select the terrain editor and paint a path from start to finish that loops around the mountains. At one end, we will place the racer, and at the end we will create a trigger to detect the end of the race, as you can see in the following screenshot:

Adding NpcRacers to the mission


To make the race compelling and interesting, we will create two NPC racers to challenge the player. If it turns out well, we can build most of these with the technology we have already developed.

Each racer will need a spline to follow. Recall from the previous chapter that we developed a system for placing waypoints in the scene and using the SplineMgr script to generate a smooth curve for an NPC to follow. This will define the smooth path they traverse from start to finish. To implement the other racers in the level, carry out the following steps:

  1. Create an empty GameObject, and name it _splineDataA. Create a series of sphere game objects, and place them in a path from start to finish. Disable the mesh renderer of these objects, and then parent them all to _splineDataA.

  2. Create a second _splineData object with different path nodes so that the second racer will follow a similar but not identical route through the course. Name it _splineDataB.

  3. Parent these two...

Creating the start and finish line flags


To mark the starting and ending location of the race, we will create a giant flag Prefab and instance it in both places. The banner of the flag will have cloth physics to give it an interesting motion. If you are targeting a lightweight device such as a phone, feel free to simply replace the cloth object with a flat plane if performance is an issue in your application. In order to create the start and finish line flags, we need to perform the following steps:

  1. Create two cylindrical game objects. Set them three units apart from one another, and scale them up to a y value of 6. Name these as pole1 and pole2. In the scene view, you should see something like the following figure:

  2. Create a cloth GameObject. It will appear as a flat plane in its initial position in the editor, but when you play the game, the cloth simulation will apply the motion.

  3. Scale and rotate the cloth object so that it faces the ground at right angles. Scale the object so that it penetrates...

Creating the LevelStart and LevelFinished pop ups


Our level will use three pop-up windows to communicate with the start and finish scenarios of the level. One of them will show the start details, and the other one will explain whether you have passed or failed the objectives. We will use the Prefabs from Chapter 5, User Interfaces in Unity, as a basis for these pop ups. In order to create these pop ups, let's perform the following steps:

  1. Create a new Prefab named popup_Level2Start from the popup_info Prefab, which we created in Chapter 5, User Interfaces in Unity.

  2. Change the five lines of text on the Prefab to detail the instructions for the level: "You are in a trivia race against two other racers. Run from start to finish and answer the trivia questions. You must achieve 100 percent accuracy and place first in the race to move on to level 3. Good Luck.".

  3. On Popup Button Script, add three actions in the editor as shown in the following screenshot:

    • On the first element of the actions array,...

Creating the setupLevel2 Prefab


The setupLevel2 Prefab will be activated when the user presses the start button on popup_Level2Start. It will finish the initialization of the mission for the level in the missionMgr script. Let's perform the following steps to create the setupLevel2 Prefab:

  1. Create a new Prefab named setupLevel2. Duplicate the SetupMissionOne script from mission one, and rename the duplicate SetupMissionTwo. Add an instance to setupLevel2.

  2. Inside MonoDevelop, change the class declaration to SetupMissionTwo as shown in the following line of code:

    public class SetupMissionTwo : MonoBehavior {
  3. We will use the same pattern for choosing random QuizNpc locators as we did for the flag locators in mission one. In addition to the QuizNpc Prefabs and the spawnPoints lists, add a list of CorrectPopups to the class.

  4. This class will hold the pop ups that are shown to the user when a correct answer is given for a particular quiz question. This will be populated by the user in the editor, and...

Creating the raceStartup Prefab


Recall that the second Prefab that is enabled when the popup_Level2Start windows is clicked, is the raceStartup Prefab. This object will commence the start of the other racers, leaving room for an eventual countdown clock. Let's start creating the raceStartup Prefab by performing the following steps:

  1. Create a new empty GameObject named RaceStartup.

  2. Create a new script named RaceStarterScript, and add an instance of it to the raceStartup class.

  3. This class should have a number of public variables to permit the tweaking of the race start.

  4. In the following line of code, stageTime is the amount of time each stage lasts:

    public float stageTime = 2.0f;
  5. In the following line of code, numStates is the number of states (of duration stageTime) that need to pass before the NPCs are activated:

    public int numStages = 4;
  6. In the following line of code, currentState tracks which actual state is currently elapsing:

    public int currentState = 0;
  7. Add a float t to track elapsed time as shown...

Implementing the LevelLogicObj GameObject


When instantiated, the LevelLogicObj object will be detected as soon as the player and racers enter the LevellogicObj's trigger volume. When three racers have crossed the finish line, it will determine if the player has met the objectives of the race or not, and it will enable either the pass or fail retry pop up. In order to implement the LevelLogicObj object, we need to perform the following steps:

  1. Create a cube game object named LevelLogicObj. Scale, orient, and position it so that it surrounds the finish line in the level as shown in the following screenshot:

  2. Make sure it has a Box Collider component and that the Is Trigger checkbox is checked as shown in the following screenshot:

  3. We want to use the DecisionMgr class to track the progress of the racers, which means we need to add an instance of npcScript to this object.

  4. Don't worry about the fact that the LevelLogicObj object is not specifically an NPC; if an existing tool is appropriate, don't reinvent...

Summary


We have finished mission two in our e-learning game, which tests the user on the learning that occurred in mission one by developing a race-based quiz game. The elements of fun and pressure are deliberate design considerations as they allow the designer a way to adjust the fun factor of the game to enhance learning.

In the next chapter, we will change focus and learn about how to add models and animations to the placeholder characters and objects in our game in order to make them more visually appealing.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Creating E-Learning Games with Unity
Published in: Mar 2014Publisher: ISBN-13: 9781849693424
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
David Horachek

David Horachek is a video game software developer with over 13 years of experience in programming arcade, home console, and portable games. He has programmed game projects published by Midway Games, EA, Ubisoft, SEGA, and others. He develops games under the Arbelos Interactive label.
Read more about David Horachek