In the previous step, we created an NPC that can move forward, rotate left, and rotate right when it receives commands. Now in this step, we'll set up gameboards that the character can move around on.
For this game, the gameboard needs to know and manage the following:
Tile Size: How big the tiles on the board are so the character knows how far to move.
Camera: What camera to use when the character reaches this gameboard. For this, we use the Fixed Point Camera device.
Start Position: The position where the character should start on the board. For this, we use a Creative Prop so we can easily set it as an editable property and get its transform.
End Goal: The end goal for the character to progress towards which signals the end of the gameboard. For this, we use a Trigger device that signals when the character steps on it.
Obstacles: Obstacles prevent the character from immediately reaching the end goal. These are explained in more detail in Creating Obstacles.
Each of these are tracked in the gameboard's class. The class has the concrete specifier so it can be an editable property on a Verse device, and each class member has an editable attribute to be able to change their values from UEFN.
# This class represents the gameboard and how it behaves.
# This class has the concrete specifier so it can be an editable property on a Verse device.
gameboard<public> := class<concrete>:
# The size of each tile on the gameboard. By default set to
# the default Fortnite tile size of 512x512x384.
@editable
TileSize<public>:vector3 = vector3{X:=512.0, Y:=512.0, Z:=384.0}
# The fixed point camera that provides a top-down view of the gameboard
Now that the gameboard is defined with its properties, let's add its behavior:
Handling end goal: When the gameboard is set up, we'll subscribe to the End Goal's
TriggeredEvent. We use an event handler and a custom event to signal publicly that the end goal was reached when the trigger device is triggered by the character. For more details, check out Coding Device Interactions.Starting gameboard: When it's the start of the gameboard, assign the Camera device to all players.
Ending gameboard: When it's the end of the gameboard, remove the Camera device from all players.
The following is the complete class for gameboard:
# This class represents the gameboard and how it behaves.
# This class has the concrete specifier so it can be an editable property on a Verse device.
gameboard<public> := class<concrete>:
# The size of each tile on the gameboard. By default set to
# the default Fortnite tile size of 512x512x384.
@editable
TileSize<public>:vector3 = vector3{X:=512.0, Y:=512.0, Z:=384.0}
# The fixed point camera that provides a top-down view of the gameboard
Creating Obstacles
Obstacles prevent the character from immediately reaching the end goal. We use Barrier devices as the obstacles in this game to block the character from moving, and Trigger devices that deactivate the barriers.
Our definition of the obstacle class includes:
IsObstaclePassed: Data for storing whether the barriers are currently activated or deactivated. Logic type because there are only two states.
Barriers: Barrier devices associated with the obstacle. This means you can have more than one barrier device attached to a trigger that deactivates them.
BarrierDissolves: Cinematic sequences to play when obstacles are passed.
BarrierAppears: Cinematic sequences to play when obstacles are reset.
Trigger: A Trigger device for the character to reach to deactivate the obstacle.
The following is the complete class for representing obstacles, and the class has the concrete specifier so it can be an editable property on a Verse device.
# An obstacle on the gameboard, with an associated set of
# Barrier devices, Trigger devices that deactivate the barriers,
# and Cinematic Sequence devices that play sequences for barriers dissolving and appearing for visual feedback on what is happening.
# This class has the concrete specifier so it can be an editable property on a Verse device.
obstacle := class<concrete>:
# Data for storing whether barriers are currently enabled/disabled.
var IsObstaclePassed:logic = false
# The array of barriers for this obstacle.
Adding Gameboards
Now that the gameboard is defined, you can add an array of these gameboards to your Verse device, which you'll see later in 6. Managing the Game Loop.
In the project you created from the VKT - Verse Device Starter Games template, search in the Outliner for the Verse Commander Minigame device and select it to open its Details panel.
In the Details panel under Gameboards, you'll see five elements that correspond to boards in the game. Expand these elements to see what devices, cinematics, and other properties are used for the gameboard.
You can add gameboards by selecting Add Element for Gameboards, to add more levels to the game.
You can remove gameboards by selecting the dropdown next to the gameboard you want to remove, to remove levels from the game.
You can also reorder the gameboards to change the order of the levels in the game by holding down on the element and dragging them before or after other gameboard elements.
To test out specific levels, you can reorder the boards so the level you want to test is the first in the list.
Next Step
We've defined the gameboards and shown how to add as many as you want. In the next step, you'll learn how to design the boards to develop fun puzzles and work around limitations.