You can download the sample scene for this tutorial here or use the downloads manager to install the package into a new Lua project.
The Leadwerks entity script system allows you to attach code files to objects in the scene to give them additional properties and behavior in your game. Open the scene "ScriptExample.map" from the sample package. You'll find four simple doorways, with a blue door in the middle. The two doors in the front have no script. The two doors in the back already have the SwingingDoor and SlidingDoor scripts added to them. The two doors in the back also have a transparent box around them, with a CollisionTrigger script added to each.
If you select the Player pivot entity, you can see in the entity properties that it already has the FPSPlayer script added to it. This script will create a camera and provide player controls when the game is run.
If you select the Game > Run menu item to run the game, you can use the mouse and WASD keys to look and move around. Without any modifications, the two rear doors will open if you approach them and press the E key.
The two doors in the front don't have a script added to them yet, so let's fix that. Select the door on the right (Door4), and in the Scene tab, under the entity properties, press the Add Entity Script button. Select the Physics > SlidingDoor item and double-click on it, to add the script to the entity.
If we run the game now, we can walk up to the door and open it by pressing the E key. However, the door only opens partially. Let's exit the game and fix this.
We can see in the Back and Top viewports that the door is 192 cm wide.
Therefore, we just need to change the X component of the SlidingDoor Movement property to 192, and it should open all the way.
Run the game again, and you can see the door opens all the way now.
Let's do the same thing for the left front door, but this time we will use the swinging door script. Select the door on the left (Door3), and in the Scene tab, under the entity properties, press the Add Entity Script button. Select the Physics > SwingingDoor item and double-click on it, to add the script to the entity.
When we run the game, the door will rotate to open when we approach it and press the E key, but it's rotating around the object center. This is probably not the behavior we want:
We can see in the Top viewport that the door is 192 cm wide.
Therefore, we just need to set the X component of the Offset property to 192 / 2, which is equal to 96 cm.
When we run the game now, the door will rotate around the edge like we want:
The flowgraph editor allows you to make connections between script inputs and outputs, to set up complex sequences of events. Press the Flowgraph Editor button in the left side bar to open this tool.
In this interface, you can see visual nodes that correspond to some objects in the scene. Left-click and drag a line to connect the Collide function on Trigger1 and Trigger2 to the Open function on Door1 and Door2:
When you run the game now, simply stepping into the invisible trigger field around it will cause either of these doors to open.