Basic Game Logic

Overview

After completing this tutorial, you will be able to set up a simple mission, define the starting point of the level, assign one objective, and a load next level trigger.

The more non-linear the mission objectives are, the more time you need to spend testing them. It is therefore recommended that beginners make a linear gameplay path to start with: 1st objective, complete triggers, 2nd objective, and triggers mission end.

Adding a Spawn Point

From the Objects -> Entity -> Others section of the RollupBar, drag the SpawnPoint entity to a point in the Perspective viewport.

It is generally a good idea to use Flowgraph to script the game to spawn the player at the spawn point. Otherwise when you run the Launcher, you can be spawned at the 0, 0, 0 location coordinates within the level.

The reason this isn't automated is levels can have multiple spawn points, like one at every checkpoint, for example. So you need to define where you want the player to spawn and when.

Triggering Events

Proximity Triggers

You can use triggers to activate various actions in the Editor. This tutorial covers two main ones: ProximityTriggers and AreaTriggers. You can drag triggers also to the Perspective viewport.

Placing an Area Trigger

An AreaTrigger is split into 2 parts, the Area Shape and the Area Trigger Entity. The Trigger is placed from the RollupBar.

Next, create a Shape using the Area tool found on the Rollup Bar: Objects -> Area -> Shape, by clicking at four different spots and double-clicking the last spot to close the shape.

Next place down an area trigger from Rollup Bar -> Entity -> Triggers -> Area Trigger and assign the AreaTrigger to the shape by using the Pick function, while you have the shape selected.

Adding Logic to Triggers

Creating a Flow Graph

To define what a trigger should do, a Flow Graph needs to be created. Select the AreaTrigger we just created, and then click Create in the FlowGraph section of the Entity properties in the rollup bar, or by right clicking the entity in the viewport and selecting Create Flow Graph.

Specify a group name for the Flow Graph by clicking New or by adding it to an existing group in the list. It is good practice to organize the level in layers, and then give the Flow Graph a name that contains the layer it mainly affects.

We will create a new group called Mission.

For more information, please see the documentation on using the Flow Graph Editor.

Adding an Entity to the Flow Graph

First make sure that the AreaTrigger is selected in the Sandbox Editor. Then, in the FlowGraph window, right-click in the empty field in the middle and select Add Selected Entity.

Make sure that the AreaTrigger node can be seen, by zooming in with the mouse wheel or by setting Fit Graph To View.

The AreaTrigger node has the input events on the left side and the output events on the right side.

Adding a Mission Objective

Drag the MissionObjective entity to a place in the level where the player should go to.

Open the FlowGraph that you previously created, and then select the MissionObjective entity in the Perspective view.

Now, add the MissionObjective to the FlowGraph by right-clicking the FlowGraphs main window and selecting Add Selected Entity.

Connecting Entities in the FlowGraph

Now, move the MissionObjective object to the right of the AreaTrigger by clicking and dragging the object frame.

Once it is in place, left click & hold the Enter port in the AreaTrigger and drag the mouse to the Activate port in the MissionObjective.

The Mission Objective has several important inputs:

Input

Description

Activated

0 means objective is not activated and 1 mean it is activated.

Completed

Marks an objective in the PDA as completed.

Deactivated

Removes an objective from the PDA.

Failed

Marks an objective in the PDA as failed.

Loading a New Mission

Once the player has finished his objective, let's load the next level (obviously you could trigger another objective after the first one, but for this test; simply load the next level (forest again)).

  1. Place a ProximityTrigger over the MissionObjective node.
  2. Add the ProximityTrigger node to the Flow Graph.
  3. Connect the Enter out port of the ProximityTrigger with the Completed in port of the MissionObjective.
  4. Add a Delay node of 3 seconds.
  5. Now, add a Mission/EndLevelNew node.
  6. Connect the Completed out port to the in of the delay, then connect the out of the delay to the input trigger port of the EndLevelNew node.
  7. Select the EndLevelNew node and specify the name of the level that should be loaded in the Inputs field (Forest).

Result

When the player walks into the trigger, the next mission will be loaded.

If you press L (default key) for the mission objective HUD, you can see the missions come into your HUD and get updated when completed.

Note: This works only in the real game mode - the Editor will not load the next level.

You will get a warning in the console instead:

[SANDBOX: Warning] CCryAction: Suppressing loading of next level 'levelname' in Editor