Distance Matching: How to make your locomotion stop animations more realistic with Distance Matching
Updated: Jan 15
The demo of distance matching can refer to this video in my personal project development log:
Distance Matching is an animation playback method in which game logic drives the animation. It is mainly used for locomotion stop animation. According to the expected movement stop distance of the player, the animation corresponding to the distance is played. This way of playing ensures that regardless of the actual speed of the player, as long as the root motion of the stop animation itself is correct, the best stop animation will always be played. For the situation where the player repeatedly starts and stops, it can also have a good animation appearance.
(So, some of the stop animations in my videos have feet sliding because the animations of the original third-party assets have a sliding problem relative to the root, and I haven't had time to deal with them. When the assets are correct, such as jogging with the weapon stopping is better looking.)
Its workflow is as follows:
A. Set movement parameters:
First, you need to determine the base parameters of the player's movement component. If these values change later, our animation assets may not have the best matching results. For stop animations, you need to pay attention to the following parameters:
(Last Updated Velocity is a variable that changes at runtime, but is mainly equal to the max speed limit of the movement mode you use)
B. Measure the stop distance curve:
In the picture in the previous step, the blueprint function Predict Ground Movement Stop Location we saw is a function provided by Epic (the Animation Locomotion Library plugin needs to be enabled). It will predict how far the player will stop completely without other movement influences(such as player input) based on the above parameters. This prediction is read by the animation blueprint and used to match the best stop animation progress. Such prediction results will be consistent every time the player stops inputting movement without other influences. So if we can get this predicted result curve, and adjust our animation and related parameter curves according to this curve, we can make the animation blueprint always match the best playback result.
There are many ways to measure such a curve. You can actually record the pawn location of each frame every time the player stops, and then store it in a data format you like. You can also reverse engineer the algorithm of the Predict Ground Movement Stop Location function, directly calculate the stop distance curve yourself from max speed. I used the former method, using Sequencer to record and measure the stop distance curve, and I directly called the function Predict Ground Movement Stop Location in the character blueprint, and recorded the output value of this function to ensure the most accurate prediction value. Another advantage of recording with Sequencer is that this curve can be copied and pasted into other Unreal curve editors, including the animation curve of the animation sequence, for further editing or exporting animation data.
C. Adjust animation and animation curve:
With the stop distance curve above, the next step is to adjust the animation.
If you haven't started animating stop animations yet, copy and paste the curve measured in the previous step onto your Root node's motion, and start making your stop animation based on that. You can continue to do the rest of the animation after the curve reaches its final value, such as the part blending to Idle, etc., as long as the Root remains still after that.
After you have made your own stop animation and imported it into the engine, or if you already have a stop animation, but your stop animation itself does not contain Root Motion, create a new curve called Distance on it, and then put the Copy and paste the curve of one step, and then translate the curve on the Y axis (curve value axis), so that the final value of the curve is 0.
If you already have a stop animation containing Root Motion, you can use the animation modifier DistanceCurveModifier to automatically extract the Distance animation curve from the Root Motion. This modifier will turn the motion of your Root joint into a Distance curve.
Next, you can adjust this Distance curve according to your action pace.
D. Apply distance matching in the animation blueprint:
This step is the easiest, you need to use Sequence Evaluator to play your stop animation, and add an On Update function binding to it.
The content of the function is shown in the figure below, which basically means that when our predicted stop distance is not 0, we perform distance matching and play the most suitable pose for each frame. When our predicted stop distance is 0, we play the rest of the animation at normal speed until the end, with normally it being blending to Idle pose.
To understand this, the distance matching node will compare the actual predicted stop distance with the value in your Distance curve, and when playing the animation, it matches the frame with the closest value. So if your Distance curve is closer to the actual stop distance curve measured in step B, your stop animation will always play at speed closer to 1:1. If you animate exactly according to the curve you measured, you can guarantee that your stop animation will play almost perfectly in any situation.
In addition, we can actually see that distance matching is not limited to being used for matching with the predicted stop distance. We can use customized curves with different meanings in other ways, and play animations that match the values of these curves. I feel that this will be an idea worth exploring in the future.