Hello !
So today I went on the challenge to create the most foolproof door script possible. Basically, my goals were:
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).
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).
The next part is the logic to actually open and close the door once the player position has been registered. I've initially done it with a Flip Flop that switches from A to B to open and close the door with supporting logic if the player crossed to the other side and close the door. That became quite a complicated routing of nodes and I eventually lost a bit myself. The problem with using the Flip Flop node was that I couldn't reset the operation to A at some point. B had to follow. So instead of using this node I used an integer variable that I called Flow_Control_1 and Flow_Control_2. Each time I pressed "E", the variable would be incremented by 1 and at 2 would close the door and reset to 0. If the player opened the door in front of him, crossed over to the other side (overlapping Box 2 instead of Box 1 for example) and pressed E the door would then close (reverse the previous timeline animation) and reset every "flow_Control" variables so that the next action registered would be an "open door" animation.
See you tomorrow ! :)