First Person Exploration Kit: Creating a Door


Overview

There are 3 main types of door included with this asset. They are: Sliding, Always Swing Out, and Complex Swinging. You can also create your own type by extending the FPEDoor class.


Table of Contents


Included Example Doors

Template Type (FPEDoor.cs)This is the parent class from which all other doors are derived. It houses some common variables and functions.
Sliding Door (FPESlidingDoor.cs)This door slides. These kinds of doors are really convenient sometimes, because it's really hard for the player to get in the way. Common applications are automatic double doors, and pocket sliding doors. See demoManualSlidingDoor.prefab and demoDoubleAutomaticSlidingDoor.prefab for example use.
Always Swing Out Door (FPEAlwaysSwingOutDoor.cs)This door swings, but always swings out away from the player. These are the best kind of doors, because they are easy to configure and easy to use for players. Real doors don't usually work this way, but sometimes realism isn't that important. See demoAlwaysSwingOutDoor.prefab for example use.
Complex Swinging Door (FPESwingingDoor.cs)This door always swings, but does so in a realistic manner. They simulate "directional inswing". They are also setup to automatically move the player to a special "safe zone" where the door won't hit them. When opening toward the player, a micro "cutscene" plays, panning the cammera toward to door latch. These doors are recommended for advanced users or simulation-oriented applications. See demoDoorLeftHandInSwing.prefab and demoDoorRightHandInSwing.prefab for example use.

Common Door Components

All doors have a similar set of parts that behave in slightly different ways.

Door MeshThis is the visible "door bit" that blocks a doorway. Some doors swing this part, others slide it out of the way.
Door Handle Mesh(es)The part of the door the player looks at when interacting with the door.
Swinging or Sliding PartThis houses all the moving parts of any door (such as the door mesh, door handle(s), and other objects)
Door Handle Interaction(s) (uses FPEInteractableActivateScript component)These are the Activation type objects that allow the player to open and close the door. It's a good idea to align these with the visible door handle mesh(es), and perhaps make them even larger.
Hit Helpers (uses FPEDoorAndDrawerHitHelper component)Optional child objects that are used to detect when a door should stop.
Player Interaction ZonesOptional child transforms that designate specific spots for custom actions. Mostly used to detect which side of the door the player is closest too and where to move them, if desired.

Note: Most of the time, you want the Box Collider of your DoorHandle Activation objects to be a trigger. This will prevent it from colliding with other objects.

All doors have a shared set of Inspector Fields, as well as their own for custom behaviour.

Start Internally LockedIf true, this means the door will start internally locked, and require specificed inventory item to act as a key to unlock it.
Required Key TypeThe type of inventory item required to unlock an internally locked door.
Start Externally LockedIf true, the door will start externally locked. This means an external object such as a security system will need to unlock it before it can be opened.
Start OpenedIf true, the door will start in an Open state. You will also need to visually move the sliding or swinging part of the door to reflect this state. Good for cases where you want a door to be opened a little already to guide the player or come across a little spooky or something.
Stop If Door Hits SomethingIf true, the door will use its Hit Helpers to stop when it hits another object such as the player or blocking physics object like a Pickup.
Door Handle Interaction Text OverridesThese interaction strings are assigned to the door handle(s) when different actions take place.
Play SoundsIf true, your door will make sounds during various actions and events.
Door SoundsThese are the various sound banks that will be used to make sound effects if Play Sounds is true.

See the various types below.

Sliding Doors

This asset comes with some example Sliding Door prefabs: demoManualSlidingDoor, demoManualSlidingDoor_Locked, and demoDoubleAutomaticSlidingDoor. To use them, simply drag them into your scene. If using the _Locked variant, ensure the player has access to the required key (default is demoSimpleKey.prefab). If using the _ExternallyLocked variant, ensure there is something such as the demoSecuritySystem prefab included so that the door can be externally unlocked. Run the scene and use the doors. You're done.

To create a customized Sliding Door from scratch, follow these steps:

  1. Create a new scene, and add a Plane at (0,0,0), and an FPECore object.
  2. Create an empty GameObject, name it MyCustomSlidingDoor
  3. Add the FPESlidingDoor component. This will add come child objects: SlidingPart, and SlidingPart\DoorHandle
  4. Create an empty child of SlidingPart at (0,0,0), name it DoorMesh.
  5. Add a child mesh to DoorMesh, such as the included Door_C.fbx, and rotate it as required so that it aligns with the gizmos
  6. Add a child mesh to DoorHandle, such as the included DoorHandle_Pocket.fbx, ensure it is at (0,0,0) and rotate it as required.
  7. Your door should now look like this:


  8. Add a Box Collider to the SlidingPart object, and size it accordingly. It should be just a tiny bit bigger than the main door mesh.
  9. Select the DoorHandle object, and set the Event Fire Type to EVERYTIME, then assign the activateDoor() function of your custom door to its Activation event.


  10. Run your scene, and open the door by interacting with the door handle. The door should now slowly slide open and closed when activated.
  11. Move the door handle to the left side of the door where you want it, and make the DoorHandle object smaller as desired. Also set its Box Collider to be a Trigger.


  12. To make the door stop when it hits something, create another child object of SlidingPart and name it HitHelper.
  13. Add a Box Collider to HitHelper, and then add an FPEDoorAndDrawerHitHelper component.
  14. Scale the HitHelper object so that the yellow gizmo outline is about the same size as the door mesh, but a little thicker. Also make it stick out of the left side of the door a little.
  15. On the main MyCustomSlidingDoor object, check the "Stop if door hits something" checkbox.
  16. Run your scene again, and open the door. Now stand near the left side of the door and close the door. It should stop when it hits the player. If it doesn't, check the steps above, and try making it stick out a little more to the left. See demoManualSlidingDoor.prefab for reference.
  17. To make the door be locked, simply check the Start Internally Locked checkbox and set the required key type (e.g. SIMPLEKEY)
  18. Add a demoSimpleKey to your scene. Run the scene again, and test out the door. You now need to unlock it with the key in order for the door to open.
  19. If you want your door to make sounds, assign sound banks to the "Door Sounds" fields in the inspector. The included sound banks are in \Sounds\Soundbanks\DoorsAndDrawers\ folder.
  20. You're all done! If you want, you can further customize the fields in "Door-Specific Behaviour" section of the inspector, then save your new door as a prefab.

Note: In order for saving and loading to work correctly, your doors have to have unique names within a scene. If using a prefab, having two doors be named "MyCustomSlidingDoor" and "MyCustomSlidingDoor (1)" is perfectly fine! :)

Always Swing Out Doors

This asset comes with some example Always Swing Out Door prefabs: demoAlwaysSwingOutDoor, demoAlwaysSwingOutDoor_ExternallyLocked, and demoAlwaysSwingOutDoor_Locked. To use them, simply drag them into your scene. If using the _Locked variant, ensure the player has access to the required key (default is demoSimpleKey.prefab). If using the _ExternallyLocked variant, ensure there is something such as the demoSecuritySystem prefab included so that the door can be externally unlocked. Run the scene and use the doors. You're done.

To create a customized Always Swing Out Door from scratch, follow these steps:

  1. Create a new scene, and add a Plane at (0,0,0), and an FPECore object.
  2. Create an empty GameObject, name it MyCustomAlwaysSwingOutDoor
  3. Add the FPEAlwaysSwingOutDoor component. This will add come child objects: SwingingPart, SwingingPart\DoorHandle, PlayerInteractionZones\LeftHandSide, and PlayerInteractionZones\RightHandSide
  4. Create an empty child of SwingingPart at (0,0,0), name it DoorMesh.
  5. Add a child mesh to DoorMesh, such as the included Door_C.fbx, and rotate it as required so that it aligns with the gizmos
  6. Position the mesh so that it is centered vertically about the red gizmo as shown below, and a little bit away from it. Since Always Swing Out doors swing on a sort of imaginary hinge, we'll need to do some visual fiddling a little later on.


  7. Add a child mesh to DoorHandle, such as the included DoorHandle_A.fbx, ensure it is at (0,0,0) and rotate it as required. Duplicate it, and rotate the duplicate 180 degrees so that there are handles on both sides of the door. Move the entire DoorHandle object so that it is at the end of the door opposite the red hinge gizmo.
  8. Your door should now look like this:


  9. Add a Box Collider to the SwingingPart object, and size it accordingly. It should be just a tiny bit bigger than the main door mesh.
  10. Select the DoorHandle object, and set the Event Fire Type to EVERYTIME, then assign the activateDoor() function of your custom door to its Activation event.


  11. Run your scene, and open the door by interacting with the door handle. The door should now slowly swing open and closed when activated.
  12. Move the door handle(s) to the right side of the door where you want it, and make the DoorHandle object smaller as desired. Also set its Box Collider to be a Trigger.
  13. To make the door stop when it hits something, create another two child object of SwingingPart and name them HitHelperLeft and HitHelperRight.
  14. Add a Box Collider and then add an FPEDoorAndDrawerHitHelper component to both HitHelperLeft and HitHelperRight.
  15. Scale the Hit Helper objects so that the yellow gizmo outline is about the same size as the door mesh. Also make it stick out of the right side of the door a little.
  16. Position HitHelperLeft lower in Z axis toward the PlayerInteractionZones\LeftHandSide object's side of the door. Do the opposite with HitHelperRight.
  17. On the main MyCustomAlwaysSwingOutDoor object, check the "Stop if door hits something" checkbox.
  18. Then, position both the PlayerInteractionZones\LeftHandSide and PlayerInteractionZones\RightHandSide objects so they are closer to the door handle.
  19. Your door should now look like this:


  20. Run your scene again, and open the door. Now stand near the left-center side of the door and close the door. It should stop when it hits the player. If it doesn't, check the steps above, and experiment with the size and position of the Hit Helper objects, making them stick out a little more. See demoAlwaysSwingOutDoor.prefab for reference.
  21. To make the door be locked, simply check the Start Internally Locked checkbox and set the required key type (e.g. SIMPLEKEY)
  22. Add a demoSimpleKey to your scene. Run the scene again, and test out the door. You now need to unlock it with the key in order for the door to open.
  23. If you want your door to make sounds, assign sound banks to the "Door Sounds" fields in the inspector. The included sound banks are in \Sounds\Soundbanks\DoorsAndDrawers\ folder.
  24. Finally, you may want to hide the visible crack in the door where the hinges should go. Normally there are hinges here, but this always swing out door sort of breaks the rules of real doors a little.
  25. Add a child Quad 3D Object to SwingingPart called "GapHider" and Assign a material such as the included DoorGapHider_A.mat
  26. Remove the MeshCollider component, then scale the position the quad so it covers the crack in the door. You want to have the textured side face the opposite side of the door from its own position.
  27. Once in place, duplicate GapHider and rotate it about the Y-Axis 180 degrees, and move it to the opposite side of the door.
  28. Now when the door swings open, the gap from the missing traditional hinge will be covered up and way less noticeable. See demoAlwaysSwingOutDoor.prefab for further reference.
  29. You're all done! If you want, you can further customize the fields in "Door-Specific Behaviour" section of the inspector, then save your new door as a prefab.

Note: In order for saving and loading to work correctly, your doors have to have unique names within a scene. If using a prefab, having two doors be named "MyCustomAlwaysSwingOutDoor" and "MyCustomAlwaysSwingOutDoor (1)" is perfectly fine! :)

Complex Swinging Doors

This asset comes with some example Complex Swinging Door prefabs: demoDoorLeftHandInSwing, demoDoorRightHandInSwing, and demoDoorRightHandInSwing_Locked. To use them, simply drag them into your scene. If using the _Locked variant, ensure the player has access to the required key (default is demoSimpleKey.prefab). You're done.

To create a customized Complex Swinging Door (in this case, a Right-Hand Inswing Door) from scratch, follow these steps:

Note: Setting up one of these doors can be tedious. These types of doors are recommended for advanced users or simulation-oriented applications only.