Unreal5 third-person shooter game character basic production 2

Continued from the previous Unreal5 third-person shooter game character basic production 1
insert image description here

character crouch effect

The above is the required operation mapping. To achieve crouching, you must first enable the corresponding function. You need to enable crouching on the character movement component. There are
insert image description here
also some other settings for crouching, such as the height of the crouching character, and the walking speed after crouching.
insert image description here
insert image description here

Chinese and English screenshots
Here I set the movement speed, and I can walk out of the platform when crouching, just to prevent the problem of not being able to jump off the object.
Next, we need to implement the crouching logic
insert image description here
to obtain event input, and then judge whether it is currently crouching. This is obtained in the character movement plug-in, and then set the opposite action to realize clicking to switch the crouching state, and then set the state to the character class above.
Next make crouching blend space 1D
insert image description here

After the blending space is created, the basic part has been realized. Next, we will realize the animation blending, open the animation blueprint and enter the
insert image description here
standing basic state realized before, and realize the blending of actions here.
insert image description here
Next, drag the created blending space into it, and then Using the node, blending poses by buer, we can switch between standing and crouching poses through a Boolean variable.
According to the boolean variable, we need a boolean value to switch between crouching and normal movements, so create a boolean variable and let the
insert image description here
mixed pose node switch through this value.
insert image description here
The result is like this. Next, we only need to in the character blueprint, Just modify this value, then set whether to crouch there before, and then get the animation blueprint node, set the variable to true in the crouching state, and set it back to false in the crouching state. I took a look, if you are
insert image description here
crouching state, and then click to release the crouch, and the animation will resume. In fact, there is no contact with the crouching state. I directly use the callback to solve this problem to process the animation. We found that
insert image description here
after crouching, the camera focus is still the original position, but the character has been Crouching, so we need to use the timeline to realize that after the character crouches, the camera will move downwards.

timeline creation

Next, we need to make a switching animation. First, create a timeline.
insert image description here
Create a floating-point track in the timeline and
insert image description here
name it well. Then we need to make a transition of 0.3s, so we created two points, one is that the time is 0, and the value is also 0
insert image description here
and the other is time. 0.3 The value is 1.
insert image description here
The two buttons on the upper left can display the entire timeline, without the need for us to drag and drop to display all.
Finally, remember to change the length to the total length of the set time axis, otherwise, although your value transformation is completed, your animation will have a lot of idle time.
insert image description here
Right-click to select the first keyword, select Auto, it will automatically interpolate
insert image description here
insert image description here
Play to play directly, if you are currently playing a section, it will continue to play directly at the playback point
Play from Start Play directly from the initial position
Stop Pause sequence frame update
Reverse reverse Play
Reverse from End Play Set New Time in reverse from the end position
to set a new position New TIme is a time position defined by yourself

Update When the sequence frame is updated, Finished will be triggered for each frame.
When the sequence frame ends,
Direction will be triggered to obtain whether it is playing forward or reverse. You can switch to judge
Half Height. The name I defined personally can get the value of the current sequence frame

Implement camera offset

What we want to achieve is to modify the z-axis of the socket offset
insert image description here
. Then drag the spring arm component from the left into the blueprint, first get the value of the socket offset and input Socket Offset is the English of the socket offset.
insert image description here
Get it first and then set it, because we only need to set the z axis, and the other two axes are directly connected to keep the original value.
insert image description here
Next, we use the interpolation node to realize the value generation. When Alpha is 0, the value is A Alpha When it is 1, b is used, and the two values ​​​​are interpolated in the middle.
The specific algorithm is (b - a) * Alpha + a,
insert image description here
so that the logic of the whole crouching is realized
insert image description here
. Here, I updated the version to 5.1. The enhanced input function of ue5.1 is used, and the implementation of unreal 5.1 enhanced input can be modified as needed.

Aim offset function

The aiming offset is that the character's head will change its orientation to follow the camera's orientation, so that they are all facing the same direction. To achieve this function we will use additional animations.
insert image description here

Using additional animations, we need to offset all animations based on the forward orientation. Here I use a set of red frames.
insert image description here
If you don’t have animations, you can go to the store to find free animation packages.
Next, realize the offset implementation based on the positive orientation. How to set in batches, we need to select all resources, and then find in the asset operation to perform batch editing through the attribute matrix. Next,
insert image description here
select all assets in the window, and set the basics in the additiveSettings on the right. The pose animation is a front-facing animation, which realizes the offset of the animation based on the forward animation.
insert image description here
If you want a single setting, you can find additional settings on the animation page
insert image description here

Then create an aiming offset asset, which is used to make offset animation. Aiming offset is Aim Offset in English. We can add the prefix AO to the asset and
insert image description here
select the corresponding bone. Enter, you will find that the biggest difference between it and the mixed space 1D is The reason is that it has two coordinate axes, and
insert image description here
then the two coordinate axes are named. Here, the horizontal coordinate is named Yaw, and the vertical coordinate is named Pitch. This name is taken from the Euler angle. The horizontal and vertical ranges are -90 to 90 degrees, that is, the range in which the head can rotate is 180 degrees.
insert image description here
After the setting is complete, you will find that the characters in the scene disappear, and the additional animation, in short, needs to be attached to other animations to be useful, so we need to modify its preview basic animation, and choose an idle animation to see the effect.
insert image description here
At this point, the additional animation is done. Next, what we need to do is to implement the corresponding functions in the animation blueprint. The idea is to obtain the orientation of the character and the orientation of the camera, and perform the additional animation according to the obtained angle. offset setting.
First find out the two included angles, and then limit the range
insert image description here
. In order to solve the problem of teleportation of the head, we use interpolation tween animation transition, R interpolation to this node,
insert image description here
we can define the current current and target target, and then set the time DeltaTime as the interval Time is the interval time of each frame, Interp Speed ​​is the transition speed, 0 is no transition, the larger the value, the smoother it is.
insert image description here
The above figure creates two variables, Pitch and Yaw, to store the current offset and also serve as the value for setting additional animations. Finally, we need to assign the interpolation result to these two variables, and these two variables are implemented for Based on the offset of the camera and character, follow the offset.
insert image description here
Above we have achieved the acquisition of the value of the aiming offset node in the event graph of the animation blueprint.
Finally, we need to add the created aiming offset animation to the basic animation process to achieve animation mixing and assign values.
insert image description here
There is another problem. The aiming offset node I made earlier turned out to be a mixed space node, and it turned out to be a problem. Everyone should pay attention to it.
After the production is completed, you will find that when the camera moves to the front of the character, the character will never look at the camera. Next, let's move the camera to the front and the character's face faces forward.
After checking, it is found that the angle difference between the two Z values ​​of the camera in front of the character is -90 to -180 degrees and 90 to 180 degrees, so we directly take its absolute value to judge whether the camera is directly in front of the character
insert image description here
. Boolean variable, we can judge through the branch, if it is not greater than 100, it will still be processed according to the previous default, if the camera is directly in front, then let the face face forward, the idea of ​​​​this implementation is to let the current Yaw value also be interpolated to 0 (0 is the default value of the left and right direction of Yaw facing forward). If you need a Pitch value, you can also do this.
insert image description here
However, in the Korean game, the way they handle it, when the camera is in front, the character's face will face the camera. I will implement it next.
First, a Boolean judgment is made, that is, after the difference between the camera and the orientation is reached, switch to the face facing the camera. We only need to judge the interpolated Yaw.
insert image description here
When facing the front, we ask for the orientation of the camera's buttocks. I found through printing that the range of the camera's steering is 0 to 360 degrees for Yaw, and 0 to 90 for Pitch and 270 to 360. The reverse value of Yaw can be obtained by adding 180, and Pitch can take a negative value or subtract the current value from 360.
insert image description here
Finally, we use this reverse rotation body and the character rotation body to calculate the difference, just continue the previous steps, the following is the entire code of the current function.
insert image description here

tidy

Finally, sort out the nodes, select all the functions related to shooting offset, and fold them into functions
insert image description here
to directly generate a function from this pile of nodes. Enter the function, and you will find that these two values ​​​​are actually referenced values, but give two parameters, we want to merge together. Hold down the ctrl key, drag the node of Self 3 to Self 2,
insert image description here
then select the node and rename it on the right,
insert image description here
click compile, after compiling, an error will occur in the place called externally, here we need to refresh the node to solve the error
insert image description here
problem, basic The action and movement functions have been completed, and the shooting function of the character will be updated later.

Guess you like

Origin blog.csdn.net/qq_30100043/article/details/130911535