February
17
2015

You can create automatic doors that open when the player comes near them and close when the player goes away using the Event System.

To achieve this, we need two simple events that will move the door game object on Trigger Enter and Trigger Exit event interactions. In this tutorial, we’ll create an automatic door that slides up and down – you can create other doors the same way with a different event setup, e.g. sliding them sideways or use a Rotation Step to rotate them open instead.

Open door event

This event is used when the player enters the trigger of the door and will move the door upwards. The event and the door will be two separate objects, allowing us to use the event object as reference position for the door movement. Open the ORK Framework editor and navigate to Events. Click on New Game Event to create a new game event.

gameplay_12_automatic_doors1

Event Settings

We need two actors, click on Add Actor to add the first actor.

  • Type
    Select Object.
  • Event Object
    Enable this setting.

Click on Add Actor again to add the 2nd actor.

  • Type
    Select Object.
  • Event Object
    Disable this setting.

Change Position

Add > Movement > Movement > Change Position

  • Object (Moving Object)
    Select Actor.
  • Actor
    Select 1: Scene Object.
  • To Object
    Enable this setting.
  • Object (Target Position)
    Select 0: Event Object.
  • Local Space
    Enable this setting.
  • Offset
    Set to X=0, Y=4, Z=0.
    This will move the door upwards by 4 world units.
  • Move
    Enable this setting.
  • Wait
    Disable this setting.
  • Ignore Y
    Disable this setting.
  • Controller Move
    Disable this setting.
  • Face Direction
    Disable this setting.
  • Time (s)
    Set to 1.
  • Interpolation
    Select Ease In Out Quad.

And that’s it for this event – click on Save Event and save it as doorUp in Assets/Events/Scene/.

Close door event

This event is used when the player exits the trigger of the door and will move the door back to the original position (i.e. the event’s position). Since this event is the same as the other except for one single setting, we’ll just edit the previous event and save it as a new event.

Change Position

Change the following setting.

  • Offset (Target Position)
    Set to X=0, Y=0, Z=0.

And that’s it for this event – click on Save Event As … and save it as doorDown in Assets/Events/Scene/.

Scene setup

We’ll add a door to the entrance of the town, so open the town scene (1 Town, can be found in Assets/Tutorial Resources/Scenes/) and add an empty object to the scene using Unity’s menu: Game Object > Create Empty

Change the following settings.

  • Name
    Set to Door Event.

Transform

  • Position
    Set to X=30.5, Y=6, Z=9.5.
  • Rotation
    Set to X=0, Y=350, Z=0.

Box Collider

Add a Box Collider component and change the following settings.

  • Is Trigger
    Enable this setting.
  • Size
    Set to X=8, Y=8, Z=8.

Now, create a new game object, this time it’ll be a CubeGame Object > 3D Object > Cube

Make the new cube a child object of the Door Event game object by dragging it onto the event object in the scene hierarchy. Now change the following settings.

  • Name
    Set to Door.

Transform

  • Position
    Set to X=0, Y=0, Z=0.
  • Scale
    Set to X=5, Y=5, Z=1.

gameplay_12_automatic_doors2

Door Up Interaction

Now, select the Door Event game object again and add an Event Interaction component.

  • Event Asset
    Select doorUp.

Click on Ok and change the following settings in the interaction’s inspector.

Event Settings

  • Start Type
    Select Trigger Enter.
  • In Blocked Control
    Enable this setting.
    The event will also be executed when the control is blocked, e.g. during scene change.
  • Turn Player to Event
    Disable this setting.

Actor Settings

  • Actor 1
    Select Door (game object in the scene).

Door Down Interaction

Add another Event Interaction component.

  • Event Asset
    Select doorDown.

Click on Ok and change the following settings in the interaction’s inspector.

Event Settings

  • Start Type
    Select Trigger Exit.
  • In Blocked Control
    Enable this setting.
    The event will also be executed when the control is blocked, e.g. during scene change.
  • Turn Player to Event
    Disable this setting.

Actor Settings

  • Actor 1
    Select Door (game object in the scene).

And that’s it – don’t forget to save the scene.

gameplay_12_automatic_doors3

Now, when playing the game, the automatic door will open and close each time you enter or leave the town.

Tip: Restricting access

Your automatic door should only open when the player has a certain item, e.g. a keycard?

By adding a check step (e.g. Has In Inventory – searching for a keycard item) before the door’s movement, you can keep the door closed when the item isn’t found.