So today I went on the challenge to create the most foolproof door script possible. Basically, my goals were:
- The door can be opened from both sides
- The door always opens away from the player.
- The player can open the door, cross to the other side, close it and open it indefinitely.
- The player can open the door cross to the other side, close it and go to it's first position and open it and close indefinitely.
- The systems will be used in a multiplayer game. It needs to make input possible for a multitude of player controllers (still learning Replication).
The first part was to recognize where the player would be standing. In the door BP I added two box components on each side of the door (also added two static mesh components: the frame and the pivoting door (which is set to movable)). Component BeginOverlap and Component EndOverlap events were added for each of those boxes. I then added two bool variables to the Player Controller: isOn_Side1 and isOn_Side2. Whenever the Player would overlap with one of the boxes from the door BP it would set one of those variables to true (and endOverlap would set it to false). This is mostly to know which Timeline animation to use to swing the door open (door needs to always open away from the player as it is most elegant). The next part was to have another volume (box component) that when touched would use the Enable Input node set to "self" just like in the Blueprint Office example with the button and the console. This enables the Player Overlapping to trigger key events inside the door BP. I'm not posting this section on here because I still need to work on it so the Replication works perfectly (I need to read a little more about it).