Spring arm ue4 что это
Using Spring Arm Components
The Spring Arm component is used to automatically control how the camera handles situations where it becomes obstructed.
You can use your own character for this tutorial provided it has a Camera component assigned to it. If you do not have a character, it is recommended that you complete the Working with Camera Components tutorial in order to create the basic character being used in this guide first.
In this How-to, we add a Spring Arm component and parent a Camera component to it so that our camera can expand/retract based on gameplay situations. Typically when you add a Camera component to a character for the purposes of creating a third person perspective, you will also want to include a Spring Arm to automatically control how the camera handles situations where the it becomes obstructed by level geometry or other objects in the level.
While it may not eliminate instances of the camera penetrating objects in your level, depending on your Spring Arm’s settings, it will help reduce them by moving the camera’s position when it becomes obstructed automatically and then returning to its default position when it is free from obstruction.
Continuing from the Working with Camera Components How-to, open your Character Blueprint.
In the Components window, click the Add Component button then select the Spring Arm Component.
Inside the Components window, drag your Camera Component onto the Spring Arm Component to attach it to the Spring Arm.
There are multiple settings that can be used with the Spring Arm which are outlined below.
Sockets
This allows you to parent the Spring Arm to a Bone on a Skeletal Mesh or a Socket.
Camera
Here you can set the length of the Spring Arm when there are no collisions as well as set Offsets.
Camera Collision
Set whether or not to check for collisions and define how big the query probe is to check for collisions.
Camera Settings
Whether or not to inherit Pitch, Yaw, or Roll from the Parent or Use Pawn Control Rotation.
Set whether or not the camera should lag behind the target position and settings associated with lag.
We set the Target Arm Length to 100 and Enabled Camera lag.
This gives us a shorter length than the default settings and also adds a bit of lag to the camera when moving around.
Click Compile and Play to play in the editor.
End Result
When moving the character, you will notice that the camera now lags slightly behind the characters movement. Also, when we move near a wall and rotate the camera, it attempts to reposition itself and moves in closer. When we are free from obstruction, it returns to its default length that we have specified in the settings.
Spring arm ue4 что это
В этом практическом руководстве по Unreal Engine будет добавлен компонент Spring Arm и родительский компонент Camera, чтобы наша камера могла приближаться или удаляться от персонажа в зависимости от игрового процесса. Как правило, когда вы добавляете компонент Camera к персонажу в целях создания перспективы от третьего лица, вы также захотите включить некий механизм, чтобы автоматически управлять тем, как камера обрабатывает ситуации, в которых ей мешает геометрия уровня или другие объекты в уровень.
Хотя это может не исключить все случаи проникновения камеры в объекты на вашем уровне, в зависимости от настроек вашего Spring Arm, это поможет уменьшить их, перемещая положение камеры, когда она перекрывается другими объектами, и затем возвращая ее в положение по умолчанию, когда препятствие остается позади.
Пошаговое руководство по добавлению Spring Arm в свой проект.
1. Откройте свой проект и выберите для редактирования Blueprint своего персонажа.
2. В окне Components нажмите кнопку Add Component, затем выберите компонент Spring Arm.
3. В окне Components перетащите компонент Cmera на компонент Spring Arm для его привязки к Spring Arm.
4. Есть несколько настроек, которые можно использовать с Spring Arm, они описаны ниже.
Название | Описание |
Sockets | Позволяет привязать Spring Arm к Bone или к Skeletal Mesh, или к Socket. |
Camera | Указывается длина Spring Arm, когда нет столкновений, а также установить смещения. |
Camera Collision | Задается нужно ли проверять наличие коллизий и определить уровень проверка запроса для проверки коллизий. |
Camera Settings | Whether or not to inherit Pitch, Yaw, or Roll from the Parent or Use Pawn Control Rotation. |
Lag | Указывается должна ли камера отставать от заданной позиции и настроек, связанных с задержкой. |
Это придвигает камеру ближе, чем настройки по умолчанию, а также добавляет немного задержки к камере при перемещении.
Конечный результат
Using Spring Arm Components
The Spring Arm component is used to automatically control how the camera handles situations where it becomes obstructed.
Choose your implementation method:
In this How-to tutorial, you will add a Spring Arm Component and parent it to a Camera Component. Spring Arm Components provide functionality to your camera so that it can expand or retract based on gameplay situations. Oftentimes, you may wish to add a camera to a character for the purposes of creating a third person perspective. It is usually recommended to include a Spring Arm to automatically control how the camera handles situations where it becomes obstructed by level geometry or other objects.
In this How-to tutorial, you will add a Spring Arm Component ( USpringArmComponent ) and parent it to a Camera Component. Spring Arm Components provide functionality to your camera so that it can expand or retract based on gameplay situations. Oftentimes, you may wish to add a camera to a character for the purposes of creating a third person perspective. It is usually recommended to include a Spring Arm to automatically control how the camera handles situations where it becomes obstructed by level geometry or other objects.
You can use your own character for this tutorial provided it has a Camera Component assigned to it. If you do not have a character, it is recommended that you first complete the Working with Camera Components tutorial in order to create the basic character being used in this guide.
While it may not eliminate all instances of the camera penetrating objects in your level, depending on your Spring Arm’s settings, it will help reduce them by automatically moving the camera’s position when it becomes obstructed and then returning to its default position when it is free from obstruction.
Creating the Spring Arm Component
Continuing from the Working with Camera Components How-to tutorial project, open your BP_CameraCharacter Blueprint.
In the Components tab, click the Add Component button then search and select the Spring Arm Component. Rename your component SpringArmComp.
Inside the Components tab, drag your CameraComp Component onto the Spring Arm Component to attach it.
With the SpringArmComp selected in the Components tab, navigate to the Details panel. There are multiple settings that can be used with the Spring Arm Component which are outlined below.
Sockets
Provide the capability to parent the Spring Arm to a Bone on a Skeletal Mesh or a Socket.
Camera
Set the length of the Spring Arm when there are no collisions as well as set Offsets.
Camera Collision
Set whether or not to check for collisions and define how big the query probe is to check for collisions.
Camera Settings
Set whether or not to inherit Pitch, Yaw, or Roll from the Parent or Use Pawn Control Rotation.
Set whether or not the camera should lag behind the target position and settings associated with lag.
In the Transform category, change the Location value to (0,0,150), then change the Rotation value to (0,0,90).
In the Camera Settings category, click the checkbox beside the Use Pawn Control Rotation variable, when enabled the Spring Arm Component‘s parent will use the view/control rotation of the pawn (your CameraCharacter).
In the Lag category, click the checkbox beside the Enable Camera Lag variable, when enabled the camera will lag behind the target position which will result in a smoother movement.
Next, in your ACameraCharacter::ACameraCharacter constructor declare the following code.
Compile your code.
From the Content Browser, double-click your BP_CameraCharacter to open it’s Class Defaults, then navigate to the Components tab, and select your SpringArmComp.
There are multiple settings that can be used with the Spring Arm Component which are outlined below.
Setting up Character Input
To demonstrate the functionality of your newly implemented Spring Arm Component, you will need to add movement input to your character class.
Begin by navigating to Edit > Project Settings >Engine > Input, then in the Bindings category, click the + sign next to Axis Mappings to create a new Axis input.
Name this Axis Mapping MoveForward, then search and select the W key value from the drop down key mapping menu.
Click the + sign next to the MoveForward Axis Mapping to add an additional key. From the drop down menu, search and select for the S key, then set the Scale value to -1.0.
Click the + sign next to Axis Mappings to create a new Axis input. Name this input MoveRight.
Click the + sign next to the MoveRight Axis Mapping to create an additional key, and set up your Move Right key mappings and Scales using the D and S keys with values of 1.0 and -1.0 respectively, as shown in the image below.
In the Bindings category, click the + sign next to Axis Mappings to create a new input named Turn, then search and select Mouse X for the input mapping key.
In the Bindings category, click the + sign next to Axis Mappings to create a new input named LookUp, then search and select Mouse Y for the input mapping key, and set it’s Scale value to -1.0.
Next, double click your BP_CameraCharacter and navigate to the Event Graph, right-click on the graph then search and select MoveForward for your Input Axis Event.
Click image to enlarge
Drag off the Execution pin of the InputAxis Move Forward node and in the drop down menu search for and select the Add Movement Input node, then drag off the Axis Value pin from the InputAxis Move Forward node and connect to the Scale Value pin of the Add Movement Input node.
Click image to enlarge
Right click on the Event Graph, in the context menu search for and select Get Control Rotation, then drag off from the Rotator Return Value pin and in the drop down menu search for and select Break Rotator.
Click image to enlarge
From the Break Rotator node, drag off the Z(Yaw) pin and in the drop down menu search for and select the Make Rotator node, then drag off the Rotator Return Value pin of the Make Rotator node and in the drop down menu search for and select Get Forward Vector.
Click image to enlarge
From the Get Forward Vector node, drag off the Vector Return Value pin and connect it to the Add Movement Input node’s World Direction pin.
Click image to enlarge
Right-click on the Event Graph again and search for and select Move Right for your Input Axis Event.
Click image to enlarge
Drag off the Execution pin from your InputAxis MoveRight node and in the drop down menu search for and select for the Add Movement Input node, then connect the Axis Value pin from the InputAxis MoveRight node into the Scale Value pin of the Add Movement Input node.
Click image to enlarge
From the Make Rotator node, drag off the Rotator Return Value pin and in the drop down menu search for and select the Get Right Vector node, then drag off the Vector Return Value pin and connect it to the Add Movement Input node’s World Direction pin.
Click image to enlarge
Your completed Movement Input Events will appear as shown in the image below.
Click image to enlarge
Right-click on the Event Graph, then search for and select the InputAxis LookUp event node, then right-click, search and select the Add Controller Pitch Input node.
Drag off from the Axis Value pin of the InputAxis LookUp node and connect to the Val pin of the Add Controller Pitch Input node. Drag off the execution output pin of the InputAxis LookUp node and connect to the execution input pin of the Add Controller Pitch Input node.
Click image to enlarge
Right-click on the Event Graph, then search for and select the Input Axis Turn event node, then right-click, search, and select the Add Controller Yaw Input node.
Drag off from the Axis Value pin of the Input Axis Turn node and connect to the Val pin of the Add Controller Yaw Input node. Drag off the execution output pin of the Input Axis Turn node and connect to the execution input pin of the Add Controller Yaw Input node.
Click image to enlarge
Click Compile and Save.
To demonstrate the functionality of your newly implemented Spring Arm Component, you will need to add movement input to your character class.
Begin by navigating to Edit > Project Settings >Engine > Input, then in the Bindings category, click the + sign next to Axis Mappings to create a new Axis input.
Name this Axis Mapping MoveForward, then search and select the W key value from the drop down key mapping menu.
Click the + sign next to the MoveForward Axis Mapping to add an additional key. From the drop down menu, search and select for the S key, then set the Scale value to -1.0.
Click the + sign next to Axis Mappings to create a new Axis input. Name this input MoveRight.
Click the + sign next to the MoveRight Axis Mapping to create an additional key, and set up your Move Right key mappings and Scales using the D and S keys with values of 1.0 and -1.0 respectively, as shown in the image below.
In the Bindings category, click the + sign next to Axis Mappings to create a new input named Turn, then search and select Mouse X for the input mapping key.
In the Bindings category, click the + sign next to Axis Mappings to create a new input named LookUp, then search and select Mouse Y for the input mapping key, and set it’s Scale value to -1.0.
Then in your CameraCharacter.cpp implement the following logic for your ACamerCharacter::MoveFoward, and ACameraCharacter::MoveRight class methods
Next, navigate to the ACameraCharacter::SetupPlayerInputComponent method, and implement the following code.
Level Setup
To demonstrate the functionality of the Spring Arm Component, you will need to place some geometrical obstructions into your level.
In the Editor, navigate to Window > Place Actors to open the Place Actors panel.
In the Place Actors panel, select the Geometry tab, and drag a Box Brush into your level.
Click image to enlarge
In the Details panel, you can adjust the bounds of your Box Brush by navigating to the Brush Settings category, and adjusting the X, Y, and Z values.
Click image to enlarge
Next, from the Toolbar press PIE(Play In Editor).
End Result
When using WASD to move the character, you will notice that the camera now lags slightly behind the character’s movement. Also, when you navigate your character near a wall, the camera attempts to reposition itself and moves in closer. When the character is free from obstruction, the Spring Arm returns the camera to its default Target Arm Length that is specified in its default class properties.