Introduction In game development, a well-functioning camera system is crucial for providing players with an immersive experience. A camera that keeps all actors in view ensures that the gameplay remains smooth and visually coherent. In this tutorial,...
Simón López
Author
In game development, a well-functioning camera system is crucial for providing players with an immersive experience. A camera that keeps all actors in view ensures that the gameplay remains smooth and visually coherent. In this tutorial, we will guide you through the process of creating a camera system in Unreal Engine that auto-adjusts its arm length to keep actors in view. We will cover practical steps using Blueprints, delve into the theory behind the code, and explore the math involved in auto-adjusting the camera’s arm length.
1. Create a new Blueprint Class by right-clicking in the Content Browser and selecting Blueprint Class.
2. Choose Actor as the parent class, I named it BP_ExternalCam.
3. Open BP_ExternalCam and add a Spring Arm and a Camera component.
4. Adjust the Spring Arm’s length and attach the Camera to the end of the Spring Arm.

Components section on BP_ExternalCam
1. Open the Event Graph of BP_ExternalCam.
2. Add a new variable to store the actors you want to keep in view. Name it ActorsToTrack and set its type to Array of Actors.
1. In the Tick event, get the bounds of all actors in ActorsToTrack.
2. Move the camera to the center of the actors using SetActorLocation.
3. Calculate the required arm length using the formula derived from the math section (armLength = bounds.length/tan(cameraFov)).
4. Set the Spring Arm’s length to the calculated value using SetTargetArmLength.
The camera system continuously updates its position and arm length based on the actors’ positions. By calculating the center of all actors and the furthest distance between them, the camera can adjust its arm length to ensure all actors remain in view.
To calculate the required arm length, we use basic trigonometry. The camera’s field of view (FOV) can be split to form a right triangle with the actors' distance. By using the tangent function, we can determine the necessary arm length.
Determine the angles of the triangle:
1. A = 45° (FOV/2)
2. C = 90°
3. B = 45° (180 - (A + C))
Use the tangent function:
1. tan(A) = a/b
2. Rearrange to find b: b = a / tan(A)
3. Apply the formula in Blueprints to calculate the arm length.
1. Place multiple actors in the scene and add them to the ActorsToTrack array.
2. Run the game and observe the camera’s behavior.
3. Adjust parameters as needed to ensure smooth operation.
1. Camera not keeping all actors in view: Ensure all actors are correctly added to the ActorsToTrack array. You can also use GetAllActorsOfClass on the Begin Play event to get all the actors you want to track; remember to add these actors to ActorsToTrack.
2. Camera jittering: Use interpolation functions like FInterpTo for smooth transitions.
In this tutorial, we covered creating a camera system in Unreal Engine that keeps actors in view by auto-adjusting its arm's length. We explored the practical steps using Blueprints, the theory behind the code, and the math involved. Feel free to experiment and customize the camera system to suit your project’s needs.