CCW

Interacting with Objects

The first step to creating a lockable door is to create a regular unlocked door. In this lesson, we will make a door that we can open and close with a key press.

First, we need to prepare our door. Search the Content Drawer for “SM_Door” (we can change the door’s static mesh later) and double click to open the the Static Mesh editor.

Click Collision > Add Box Simplified Collision. This creates a simple cube around the door preventing the player character from walking through.

Return to the Content Drawer, create a new blueprint called “BP_Door” and set it to Actor. In the components menu on the left add a Static Mesh and Box Collision. Set the static mesh to SM_Door and scale the box collision to surround the space in front and behind it. Open up the Graph Editor.

In the Components panel on the left, right click your Box Collision and add two events – OnComponentBeginOverLap and OnComponentEndOverlap.

For both of these new event nodes drag and release from the top-right white arrow, type and select “Cast to BP_ThirdPersonCharacter”

Now we need to enable player control of the door when they are inside the collision box.

On the OnComponentBeginOverlap node Drag and release from the top right white arrow of the Cast to BP_ThirdPersonCharacter node. Type and select “Enable Input”.

Do the same for OnComponentEndOverlap, except this time, type and select “Disable Input”.

From the Player Controller arrow of the Enable Input node, drag and release. Type and select “Get Player Controller”.

Click compile. Your Event Graph should look like this.

Now that we have enabled player controller input, we now need to tell the door what to do when it receives a command.

Right-click a new blank area of the BP_Door Event Graph, Type and select “Keyboard Events E”.

Drag and release from the “Pressed” arrow of the new node. Type and select “Flip Flop”.

A Flip Flop node allows us to switch between two different states. Drag and release from the “A” arrow. Type and select “Add Timeline”. Connect the “B” arrow of the Flip Flop node to “reverse” in the timeline node. This makes B do the opposite of what A does.

We now need to set the timing for our door to swing open. Double-click the Timeline Node to enter it. Click “+ Track” and add a new Float Track.

Right click the new track and select “Add key to Curve Float” twice.

Select each key to change their Time and Value. Set the first key to a Time and Value to “0”. Set the second key’s Time and Value to “1”. Return to the Event Graph.

From the Timeline node, drag and release. Type and select “Lerp (Rotator)”.

The Lerp Rotator node allows us to set the two rotation states our timeline will switch between. For now, let’s set the “B” state Z value to 110. We can fine-tune how much our door opens later.

Now we need to tell the door what to rotate. Drag and release the return value, type and select “Set Relative Rotation (StaticMesh)”.

Finally, connect the Update arrow of the Timeline node to the top left arrow of the Set Relative Rotation node.

Your completed Event Graph should look like this.

Compile and test your door by walking up to it and pressing “E”.