banner
YZ

周周的Wiki

种一棵树最好的时间是十年前,其次是现在。
zhihu
github
csdn

UE5 Blueprint Practical: Creating Custom Camera Field of View Control

In virtual simulation and visualization systems, controlling the camera's field of view is crucial. Users typically move forward, backward, left, and right using the W, A, S, D keys on the keyboard, and use the Q and E keys for up and down movement; at the same time, they rotate the viewpoint using the right mouse button and adjust the zoom of the field of view with the mouse wheel. This article will detail how to implement these camera control functions using Blueprints in UE5.3, helping developers create a more immersive virtual environment experience.

Preparation#

Bind Axis Mapping#

Find Edit -- Project Settings -- Engine -- Input in the menu bar -- locate Axis Mappings and set it up as shown in the image below:
image.png
Here, MoveForward represents the camera's forward and backward movement controlled by the mouse WS, MoveRight controls left and right movement; MoveUp controls up and down movement; Turn and LookUp control the camera's left-right and up-down rotation, respectively; Zoom controls the camera's field of view zoom.

Create Camera Control Blueprint#

Create a Blueprint class that inherits from Pawn, named BP_CamController.
Open the Blueprint and add components: add SpringArm, FloatingPawnMovement, and Camera (as a child component of SpringArm), as shown in the image below:
image.png

Blueprint Node Connections#

Implement Camera Forward, Backward, Left, and Right Movement#

In the event graph, right-click to input MoveForward and MoveRight to add WASD input events, and connect the relevant nodes as shown in the image below.

image.png

Implement Camera Up and Down Rotation#

In the event graph, right-click to input Turn and LookUp to add mouse X and Y events, and connect the relevant nodes as shown in the image below.

image.png

Implement Camera Up and Down Movement#

In the event graph, right-click to input MoveUp to add QE input events, and connect the relevant nodes as shown in the image below.
image.png

Implement Camera Field of View Zoom#

In the event graph, right-click to input Zoom to add mouse wheel input events, and connect the relevant nodes as shown in the image below.

image.png
(SpringArm is a reference to the spring arm component)

Place the Camera Blueprint in the Scene#

Find BP_CamController in the content menu and drag it to an appropriate position in the scene. In the details panel, find the Pawn section and check Use Controller Rotation Pitch and Use Controller Rotation Yaw, and set Auto Possess Player to Player 0.

image.png

If you want the camera to move more smoothly, you can select the SpringArm component and enable Enable Camera Lag and Enable Camera Rotation Lag in the lag section, and you can also set the corresponding smooth speed.
image.png

Run the project to control the camera's field of view using the mouse and keyboard, and make further adjustments as needed.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.