【UE4】Click the button to switch the camera and control the rotation of the new camera with the mouse

Effect

step

First created 4 Actor blueprint classes

Each blueprint class has only one camera component

Place each actor blueprint class in the appropriate position of the scene

Create a custom event in the level blueprint that switches the camera when the event fires

Create a control blueprint, create the following 5 buttons in the control blueprint, and create a click event. The buttons represent the 4 cameras on the car and the Pawn that moves freely outside the car

The button click event is as follows

At this time, the effect is as follows:

If we want to control the rotation of the lens to adjust the angle of view when switching to other lenses, we can do the following:

First, I changed the 4 cameras arranged in the car from the "Actor" class to the "Pawn" class

Similarly, each Pawn has only one camera component

Add the following custom event logic to the event graph to control the relative rotation of the Pawn itself when the event is triggered

Then call the above custom event every frame, and pass the X and Y values ​​of the mouse into the custom event

In the level blueprint, when the custom event of "entering the main driving" is triggered, the control of the Pawn is obtained

Then, click the button of the control blueprint to trigger custom events such as "enter the main driving" in the level blueprint

The final effect is as shown at the beginning of the article.

Guess you like

Origin blog.csdn.net/ChaoChao66666/article/details/129050287