
I set up an OnComponentBeginOverLap and OnComponentEndOverlap to detect when the player is within the collider space of the door. By enabling and disabling the character controller means we can prevent the player from interacting with the door whilst they are already in the door space.
We create variables to keep track of the door status, whether it is unlocked, and whether it has been opened. Using the Timeline node we can trigger the timeline of the door 'opening' (animation) to play. I have intentionally left the Reverse output to be blank so the door can only be opened, and not closed. This is because I want to prevent the player from locking themselves in a room and 'camping', meaning the player can find a strategic spot and wait for zombies to come to them, eliminating the level of intensity and danger.
To open the door, we are simply rotating the door on the Z axis. When we complete this, we use the FlipFlop node to alternate between setting the value of the boolean IsDoorOpen.

Using the door provided in the Starter Pack, I used the same method as the previous door. This required setting up the frame and door in the viewport, matching their positions up and adding a Box Collider to set an area for the player to be able to interact with the door.

OnComponentBeginOverlap we use a foreach loop to iterate over the array of locked doors. If the last index is less than 1, we unlock the door and destroy the actor (silver key object).

I created another Blueprint and created a Static Mesh, which I changed in the details window to the 3D model of the key I downloaded. Then using a Capsule Collider I created an area around the key that the player can walk into to pick up the key.
By adding a RotatingMovement it generates a rotation on the X axis in-game for a nice effect, giving the player some feedback that it is an item that can be picked up.


By selecting the door, I have access to the details panel where I can set the door to be locked "IsDoorLocked" (boolean) is set to true. I have also named the door SilverKeyDoor so we can tell which is the corresponding key in case we add more doors that require keys etc later on.
For the key, I have set it to have an array element containing SilverLockedDoor so our blueprint file can find it.


No comments:
Post a Comment