Door

From RPG Creation Kit
Jump to navigation Jump to search
A Door in the RPG Creation Kit.

Doors are interactive Objects that the Player and NPCs can open, close and travel through. In the RPG Creation Kit there are two kinds of Doors:

  • Opening Doors: regular doors that simply open and close in place, playing an animation.
  • Teleport Doors: doors that bring the Player and AI to another Cell, such as the entrance of a house that leads to its Interior cell. These are what physically connects your world together.

A Door is a GameObject with the "Door" component and the "RPG Creation Kit/Door" tag. You can find ready-to-use prefabs in Prefab Library/Doors/ (WoodenDoor_Prefab and EmptyDoor, which is useful as a starting point for your own new doors).

The Door component

Door 2.png

  • Obj Reference ID: the UNIQUE ID of this Door. It is used to register the Door in the Cell, to save its state, and to lock/unlock it from scripts. You can generate a new one by right-clicking on the component and selecting "Regenerate objReference".
  • Persistent Reference / Persistent Reference ID: whether this Door is a Persistent Reference, for the special cases where a Door has to be accessible at anytime (for example when an AI far away from it needs to use it).
  • Animation: the Animation component of the door, it must contain an "Open" and a "Close" clip. Leave it blank for doors that don't physically open, like teleport doors.
  • Ground Pivot: a point on the walkable surface in front of the door. It is the point an AI has to reach before being able to teleport to the linked cell. This can be blank, but if it is, the AI won't be able to use this door.
  • Locked? / Lock Level / Key: see the Locked Doors section.
  • Teleports? / To Cell / Teleport Marker: see the Teleport Doors section.
  • Door Sounds: the AudioClips played when the door opens (Open), when it opens after being unlocked with the key (Unlocked Open), when the Player tries to open it while locked (Locked Open) and when it closes (Close).
  • Linked Door: see the Teleport Doors section.

Opening Doors

An Opening Door is the simple case: the Player interacts with it and the "Open" or "Close" animation is played. All you have to set is the Animation reference and a unique Obj Reference ID. NPCs interact with these doors too: when an AI walking its path bumps into a closed Opening Door, it will play its open-door animation, force the door open and continue on its way.

Teleport Doors

A Teleport Door connects two Cells. When the Player uses it, the interaction text will show the destination (es, "E) Door to: Vera's Farmhouse"), the destination Cell gets loaded and the Player appears next to the door on the other side. Setting one up goes like this:

  1. Enable Teleports? and assign the destination Cell in To Cell.
  2. Once the To Cell is set, the Linked Door dropdown fills up with the Obj Reference IDs of all the Doors found in the destination Cell: pick the one this door is connected to. If the list looks outdated, press the refresh button next to it.
  3. Adjust the Teleport Marker: it is where the Player will appear when arriving through the linked door, shown in the Scene View as a cube gizmo with a blue arrow pointing forward. Place it just in front of the door, on the ground, with the arrow facing away from it.

Remember that the link goes both ways, so the door on the other side must be set up in the same manner, with its To Cell and Linked Door pointing back to this one (this is not strictly mandatory, but the only case I can think of not doing that would be some magical puzzle you'd want to make).

The Teleport Marker child is created automatically when you add the Door component, so you only have to move it in place. The inspector also offers two extremely convenient buttons, View Linked Door and View Linked Teleport Marker, which open the destination Cell and select the linked object for you, so you can check both sides of the connection without hunting for them manually.

Note: a Teleport Door doesn't need an Animation, the screen fades while the destination loads. You can leave the Animation field blank.

Locked Doors and Keys

A Door can be Locked. When the Player tries to open a locked door:

  • If its inventory contains the Key (a Key Item assigned in the Key field), the door unlocks and opens, playing the Unlocked Open sound.
  • If it doesn't, an Alert Message tells the Player he doesn't have the key, and the Locked Open sound is played.

The Lock Level (from VeryEasy to Impossible) defines how hard the lock is. It is part of the door state and is stored in the SaveFile, but keep in mind that at the moment the Player can only get through a locked door with its Key. Maybe in a future update we'll have a lockpicking mechanic based on the Lock Level.

Doors can also be locked and unlocked at runtime, without the Player being involved:

  • From a script: the RCKFunctions methods LockDoor(doorID, lockLevel) and UnlockDoor(doorID) work on any door, loaded or not: if the door is not loaded, the SaveFile is edited directly, and the door will reflect the change the next time it loads. A good example is the CityInterior_LockShopsAtNight script of the Demo, which locks the doors of the shops during the night and unlocks them in the morning.
  • From a Consequence: the Consequences System has the dedicated LockDoor and UnlockDoor Consequence types, so you can do the same from your quests without writing code.

Doors and the Save System

You don't have to do anything for doors to persist other than making sure every door has an UNIQUE Obj Reference ID. Every time a Door is opened, closed, locked or unlocked, its state (isOpened, isLocked, Lock Level, even the current point of the animation) is saved in the SaveFile under its Obj Reference ID. When the Cell loads again, the door restores itself from that data, so a door left open stays open.

Since the saved state of a Door is just a few variables, it is also the classic example of an object you can edit while it is not loaded. The LockDoor/UnlockDoor functions above create the save data on the fly if the Player has never interacted with that door. This is discussed more in depth in the Persistent References page.

Registering the Door in the Cell

Like the other objects with an ID, Doors are registered in the All Doors dictionary of the "Cell Information" component of their Cell. After placing your Doors, run Update the Cell and they will be registered automatically by their Obj Reference ID. This registration is what allows the rest of the kit (RCKFunctions, Consequences, AI) to find a door by its ID, so don't forget it!