UE4 control door opening and closing (collision detection + key input)

1. Blueprint-New Blank Blueprint Class-Actor
2. Overall logic: When the player enters the effective detection range, the door can be opened by pressing the button; in the same way, when the player leaves the detection range, the door is closed by pressing the button again.
2.1 Switch (Gate)
When the player is in the target range, the Gate is valid, so it is connected to the Open node; similarly, when the player is outside the range, the Gate is invalid, so it is connected to the Close node.
2.2 Key input
Directly input the desired key name (E)
Insert picture description here
Insert picture description here

2.2 Turn on the player's key input, use EnableInput (enable input) and DisableInput (disable input).
2.3 The reason why the button responds is because there is a player's controller, so the player controller must be obtained.

Insert picture description here
2.4 To achieve the "Cycle Open and Close Door" setting, the first time is to open, the second time is to close, and the third time is to open. FlipFlop node.

Play: Play the animation in forward sequence, start from the current progress.
Reverse: Play the animation in reverse order, start from the current progress.

PlayfromStart: The animation is played in sequence. If it is the middle part of the animation, it will first go back to the 0th stitch and then start playing
ReversefromEnd: Reverse animation. If it is the middle part of the animation, it will first return to the last stitch and then start to play backwards.

Insert picture description here

2.5 Use the time axis to control the rotation of the door, and the difference angle. See the previous article for details.

2.6 How to use:
Save the level, after the compilation is complete, drag the Actor to the scene to use it.

Guess you like

Origin blog.csdn.net/qq_22975451/article/details/113872273