Adding Open and Close Scripts

You need to add three Lua scripts to the trigger entity that you created. To do this,
you add the Lua Script component three times and then select the script for
each component.

The first script that you add (TriggerEvent.lua) tells the trigger area what events to execute when a player enters and exits the
area.

The second and third scripts that you add (MoveObject.lua) define those events specified in the first script, and link them to a script that
moves the door. The
OpenExitDoor script moves the Z position of the door so that it disappears up into the structure.
The CloseExitDoor script moves the Z position back to its
original, closed position.

A list of options appears below the Properties heading in the Lua Script component.

For now, you'll configure the EventNameExit and EventName properties with names that you'll later define with the
MoveObject.lua script. These can be any name you like; they just have to match the event names you
configure in a later step.

Set the following options:

EventName – Type OpenEntryDoor

EventNameExit – Type CloseEntryDoor

TriggerOnExit – Selected

TriggerOnEnter – Selected

TriggerOncePerEntity – Unselected

These settings configure the named events to be triggered upon entry and exit.

The TriggerOncePerEntity, when selected, sets that trigger volume to trigger just once by that entity, in
this case the player character. Some game events
may require this based on design.

Next, you'll add the script that moves the door into its open position.

A list of options appears below the Properties heading in the Lua Script component.

As stated previously, the EventName can be any name you like, though it must match the EventName in the
TriggerEvent.lua property.

Set the following options:

EventName – Type OpenEntryDoor

PositionOffset – Change Z to 3.00

When the OpenEntryDoor event is triggered, this script moves the Target, which you define as the door in the next tutorial. The target
is moved to an open position, which is determined by the relative offset that is specified
by the PositionOffset values.

In the third Lua Script component, add the same MoveObject.lua script as you did for the previous Lua Script
component.

A list of options appears below the Properties heading in the Lua Script component.

Set the following options:

EventName – Type CloseEntryDoor

PositionOffset – Set X, Y, and Z to 0.00

This script moves the Target back to its original, closed position when the CloseEntryDoor event is triggered.