Adding a Code Door to Your WorkAdventure World
In this tutorial, we'll guide you through the process of adding a code door to your WorkAdventure world. This door will require a specific access code to open, enhancing the interactivity and security of your virtual space. We'll be using a pre-fab project where all relevant objects, layers, and properties are prepared. Let's get started!
Step 1: Preparation
Before diving into the code, ensure you have the following:
- WorkAdventure Starter-Kit: Your map should be built on the WorkAdventure Starter-Kit to have a ready-to-use API.
https://github.com/workadventure/map-starter-kit
- Tiles and Assets: Make sure the "door_closed" layer uses a default WorkAdventure Tileset. When copying the door, replace the door assets from a tileset already embedded in your
map.tmj
.
- Codedoor prefab: get the predefined template from our GitHub to get started. It contains a template that you can copy over to your Tiled Project.
Clone the project here https://github.com/KomponentAB/wa-pwdoor-prefab or download the
codedoor prefab.tmj
if you are already building in a mapstarterkit based map.
codedoor prefab.tmj
Step 2: Setting Up the Door Variables
- Add the Codedoor to your map: To add the door, please copy: "Door" Layerfolder, Doorsteplayer, pw_door Object in the floorLayer. Make sure you've also transferred ALL Variables and Custom Properties.
- Define the Door Variable: Ensure you have a door variable defined on the
floorLayer
. This variable should have the type variable
and must be named exactly as you intend to use it.
- Custom Properties: The door variable should have the following custom properties:
doorVariable
: This should match the name of your door variable.
code
: The access code required to open the door.
zone
: A unique identifier for the door zone.
Step 3: Configuring the Tile Layers
- Edit/Create Doorstep Layers: The template comes with a simple doorstep-Layer. It is defined to open a Codefield whenever a player steps on the field. If a player leaves this field, the door closes, if it has been open while the player steps off the layer.
- (Optional) If you want to build more complex door behavior, you can add multiple doorsteps. Define two different layers inside a folder called
doorsteps
:
outside_doorstep
: The area outside the door.
inside_doorstep
: The area inside the room.
- Place Tiles: Place tiles on these layers where the door should open or close when a Woka (player) steps on them.
<aside>
🔥 Important: The Codedoor cant be close to a START Area. Keep at least one Tile Distance.
</aside>
(optional) Step 5: Additional Properties