Skip to content

Tutorial ‐ Step 2

Arthur Brugière edited this page Mar 8, 2024 · 23 revisions

Step 2: Creation of the Unity basic game

Creation and setting of the project

To start the creation of the Unity game, a first step consists in cloning or just downloading the Simple template Unity, branch 2024-06 and add it in the Unity Hub. You can then open it.

Download

This project includes 3 important scenes (Assets/Scenes folder): The "Start Up" menu, which is the scene launched at the start of the game; the "IP Menu", which lets you configure the IP of the computer running GAMA or the middleware; and the "Main Scene" in the Demo folder. In this tutorial, we will only modify the latter scene.

TutorialScene

Player agent settings

By default, the “Main Scene” includes an FPS player. This type of player is subject to gravity and moves at ground level, considering geometries with a collider as obstacles. In our case, we prefer to have a “decision maker” view from the sky. We will remove the FPS player (right-click it and then delete). In Assets/Resources/Prefabs/GAMA Link/Player, drag and drop the "GodViewPlayer" into the scene.

TutorialPlayer

Game manager settings

In the main scene, inspect the “Game Manager” in “Managers”. In the Simulation Manager, drag and drop the GodViewPlayer game object from the Main Scene to "Player". In this tutorial, we want to use the same coordinate in GAMA and Unity, we thus set GAMA CRS Coeff X, Y to 1.0; GAMA CRS Offset X,Y,Z to 0.0.

TutorialGameManager

An important point to note concerns the tags used in the model, particularly those sent with the geometries: these must have already been defined in the Unity project. To define a new tag, just inspect any game object in the scene, then in "Tag", select "Add Tag". Then click on the "+" at the end of the tag list and define the new tag.

TutorialAddTag1 TutorialAddTag2

In this tutorial, we will just add a new tag called "road" for the road agents. TutorialAddTagRoad

Debug Overlay

By default, the main scene includes a game object called "Debug Overlay", which displays all messages written in the C# script (with the command Debug.Log("my message") ;). In this tutorial, we won't be using it, so you can either remove the "Debug Overlay" game object from the scene, or disable it by unchecking it in the inspector (when you select "Debug Overlay" in the scene, uncheck the box to the left of "Debug Overlay" in the inspector). If you still wish to use it, you must define for the game object "Debug Overlay" (in the Inspector), the rendering camera: drag the "GodViewPlayer/XR Origin (XR Rig)/Camera Offset/Main Camera" component into this attribute.

TutorialDebugOverlay

GodViewPlayer

In this tutorial, we'll be using the GodViewPlayer game object to represent the player, which allows the player to move horizontally with the right joystick and vertically with the left. The first thing we'll do is define the player's initial vertical location. To do this, inspect the GodViewPlayer game object and change the position Y value to 200. We'll also change the movement speed to make it faster. In "GodViewPlayer/XR Origin (XR Rig)", set the "Move Vertical" script speed to 10 and the "Move Horizontal" script speed to 20 and the rotation speed to 10.

TutorialGodViewPlayer

Test of the model

The model can be launched in different ways: from a headset/directly from unity in play mode - with/without middleware. The middleware makes it possible to manage multiple connections and in particular multi-player game. However, its use requires launching third-party software (middleware). As the objective of this tutorial is to launch a game with a single player, we will just use the direct connection to GAMA.

We will see in the following two ways to launch the game: from Unity in play mode; from a VR headset. In all cases it will be necessary to launch the simulation from GAMA before, i.e. start the "vr_xp" experiment of model "traffic_model-VR.gaml".

Without the headset (debug mode) and Without the middleware

Inspect the "Managers/Connection Manager" from the "Main Scene" and check the box "Desktop Mode".

ConnectionManager

You can now push on the "Play" button of Unity.

With the headset and Without the middleware

Inspect the "Managers/Connection Manager" from the "Main Scene" and uncheck the box "Desktop Mode".

Open the 3 Scenes (Startup Menu, IP Menu and Main Scene) and connect the headset to the computer (and authorize the connection). In the File Menu, choose "Build Setting". In this panel, select "Android" then click on "Switch platform". In the "Scene in Build" panel, be sure to have the three Scene (first, Startup Scene, then IP Menu and at last, Main Scene). Then, click on Build and Run.

Build-setting

Clone this wiki locally