UE4 control door opening and closing (collision detection + mouse click)

Function: Click the door model to control the door switch

1. To register an event on the model that needs to be clicked, you
first need to add a click event to the door model, click on the door model to be rotated, and you will see Events in the interface. Click "+" to register the event in OnClicked, and it will be in the blueprint. The OnClicked (the name of the door model) node appears automatically.
The logic is also the odd number of times to control the door opening, the even number of times to control the door closing, and the OnClicked node is connected to the Gate (switch).

Insert picture description here

2. Turn on the event of the player's click operation in the player controller.
Because it is based on the third-person controller, go back to the scene and find WordSettings.
Note: WordSettings can be found in the menu Window

2.1 Set GameModeOverride to ThirdPersonGameMode.
2.2 PlayerControllerClass can't be opened with the visual interface because of the written C++ class, so click "+" to create a new class. After opening, you will see the interface about mouse settings.
Because of the mouse click operation, check EnableClickEvents and set it to true.
You only need to show the mouse when you click, and the mouse doesn't show up during the rest of the time, so ShowMouseCursor is false by default, and it is not checked.

Insert picture description here
3. Set the mouse display and hide in the blueprint.
When the player is in the detection area of ​​the door model, set the mouse to display, and set the node SetShowMouseCursor to true.
After the mouse is displayed, turn on the mouse click, and set the node EnableInput to true. Then turn on the switch (Gate) that controls the animation of the door.
When the player is not in the detection area of ​​the door model, the same is true.

Insert picture description here

Guess you like

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