Hello, I am Jose Villarroel, animation gameplay programmer at Epic Games. The animation systems in the new free sample project Lyra Starter Game showcase the current state of how we build games in Unreal Engine 5 in a way you can extend into your own projects (Download the project here). This blog post will walk you through the mindset and tools used to turn the Fortnite and Paragon-inspired strafing character into a forward-facing one, similar to what you saw in The Matrix Awakens: An Unreal Engine 5 Experience.
Strafing animation
Forward-facing animation
For more information on the individual parts we’ll be modifying, and to get more familiar with the Animation Blueprints we’ll be covering, you can see Animation in Lyra.
Replacing animations
We’re going to need different animations to implement the new locomotion style. You could make your own, but for simplicity, I’ll be migrating the locomotion animation set from the new City Sample.
Note: Default Migration settings includes a lot of unneeded extra assets, like sounds used by Animation Notifies. You can uncheck those, but you’ll have to replace references manually.
The CitySample player character covers a lot of what we’re missing for a forward-facing set, such as directional starts.
The animation assets in City Sample are parented to a different Skeleton Asset, so we’ll have to do some form of retargeting from one skeleton to the other. Fortunately for us, they have identical partial hierarchies (If they didn’t, we could use IK Rig Retargeting instead), so we’ll be able to use Compatible Skeletons, which is new to UE5. Let’s open up SK_Mannequin to add SK_Base to its compatible skeletons.
Next, we’ll make a new Linked Layer Animation Blueprint base, for any AnimGraph differences in the forward-facing version. Let’s duplicate ABP_ItemAnimLayersBase (I’m naming it ABP_ForwardFacing). For simplicity, I’ll be filling out the animation asset references in the Class Defaults with those from the unarmed set in ABP_UnarmedAnimLayers, and replace AnimSet - Starts/Stops/Jog in ABP_ForwardFacing (under Class Defaults) with the CitySample ones.
Lyra uses Distance Matching, so we are also adding Distance Curves to all of our new jog cycles, starts, and stops. This is done by adding a Distance Curve Animation Modifier to each animation, and can be done in bulk by selecting all the Animation Sequences in Content Browser > Right Click > Animation Modifiers > Add Modifiers.
The Distance Curve Modifier and the generated Distance Curve.
Adapting the Character Blueprint
Characters in Lyra’s Shooter Game mode always look where the player is aiming. This is not ideal for a forward-facing character, so we’ll take a look at B_Hero_ShooterMannequin, and change some Character Movement settings. Let’s enable Orient Rotation To Movement in the Character Movement Component and disable Use Controller Rotation Yaw in the Character Defaults.
Now we want to link our new forward-facing Animation Blueprint, but since it's not associated with a specific inventory item, we’ll make some minor adjustments to override default behavior. We’ll prevent inventory items from being added, and link our layer by default.
B_Hero_ShooterMannequin > Event Graph. Changes needed are highlighted in green.
To make things easier to look at, let’s add some debug visualization to ABP_Mannequin_Base.
Draw a black arrow for the actor’s forward and a red arrow for the mesh’s root bone forward.
Now let’s hit play and see how it looks…
Directional starts are not looking good. The character is rotating too fast, which introduces a lot of foot sliding. There’s also some occasional snapping and the animation play rates are too fast. We have three individual problems to solve: play rate, snapping, and rotation speed.
Let’s fix the play rate first. We’re using distance matching for our jog start animations. Play rate is proportional to displacement, and our character is moving very fast. In Lyra, we use a combination of play rate and Stride Warping, which enables us to dynamically adjust the pose of the character to account for differences in animation and gameplay. It is not uncommon to allow some foot sliding, since too much Distance Matching can result in very high play rate, and too much Stride Warping may stretch the pose of the character too much. This is something you can tweak, but the industry standard of playrate/stride warp adjustments is of 15-20% max increase/decrease. Values beyond that result in significant visual quality drops, and it’s often better to allow foot sliding. Let’s go for maximum quality instead and just reduce the speed and acceleration of the Character Movement Component to something more manageable. Let’s see how that looks.
Animation debugging
The play rate is definitely looking better, and the snapping is mostly gone. Instead, it looks like the start animations are barely playing. Let’s tackle that next. This sounds like a good candidate for the new Rewind Debugger.
Rewind debugger pointed us to ABP_Mannequin_Base, and by stepping back and forth, it highlights that the Start state in our State Machine is transitioning out too early. Upon further inspection, our transition rules can be interrupted based on changes in velocity direction, and character orientation, as well as Root Yaw Offset differences (see Turn in Place section in Animation in Lyra).
We are going to use this blueprint logic anywhere we want to disable something in forward-facing mode.
This makes sense for a strafing character, but not so much for a forward-facing one. Using Property Access, it’s very easy to grab the relevant properties from the Character Movement Component that we need to block these transitions. We’ll use this opportunity to remove other things that we don’t need.
We don’t want additive leans during forward-facing starts. Aim Offsets are also being disabled similarly.
ABP_Mannequin_Base > LocomotionSM > Start
Orientation Warping adjusts the orientation of the lower body to account for the difference between animated and character movement directions. In a forward-facing character, we’re looking to orient the character in the direction they’re moving in, so we no longer need Orientation Warping for starts.
ABP_ForwardFacing > Animation Layers > Full Body Start State
We’re increasing the allowed Root Yaw Offset Angle (ABP_Mannequin_Base > Class Defaults > Turn in Place). A range from -179° to 179° sounds reasonable here.
We also need to add selection for an alternative 180° start depending on whether we want to turn left or right.
Turning Not In Place
Finally, we’re going to solve rotation speed. What we want to solve is that there are big differences between the rotation speed from the Character, and the desired rotation speed from the animation. The simplest way of doing this is by reducing the rotation rate of the Character Movement Component, but this wouldn’t be the highest-fidelity solution.
Luckily for us, a solution to this exact problem was built for Lyra’s Turn in Place (see Turn in Place section in Animation in Lyra). It uses a Root Yaw Offset to counter the Character's rotation to follow the animation's rotation speed more accurately.
The main difference is that instead of doing the exact rotation the animation has been authored for, we want to adjust our animation to match the desired orientation from the player. In other words, if the player is doing a 60° rotation, and the animation chosen is a 45° start, we want to warp the rotation to cover the whole 60°, while matching the proportional speed authored in the animation.
First, we need to apply the Turn in Place Animation Modifier. I’ll be naming the generated curves RemainingTurnYawSt and TurnYawWeightSt.
Note: We are also adding these curves to SK_Mannequin manually, since they must exist in both Skeleton Assets to remap properly.
Let’s take a look at how the curves generated by the Animation Modifier are used in the Turn in Place Process Turn Yaw Curve.
ABP_Mannequin_Base > Functions > Turn In Place
We’ll duplicate this function and make some adjustments to the existing Anim Node Functions (new in UE5) to cover our new needs. First, we’ll scale the desired Root Yaw Offset delta.
During the turn portion of the start animation, we want to control the Root Yaw Offset, but when the turn is finished, we want to blend this offset out. For this, we add Reached End of Turn, which we must reset every time we trigger a new start.
ABP_Mannequin_Base > Set Up Start State is an anim node function that runs every time the Start state becomes relevant.
The Lyra Animation Blueprint has built in modes on how we want the mesh’s rotation to behave compared to the Character’s rotation through the Root Yaw Offset Mode. Now we’ll update the ABP_Mannequin_Base > Update Start Base Anim Node Function to change the mode based on whether we’ve reached the end of the turn.
Let’s take a look at the results…
This works in multiplayer, too.
Adapting your toolset
The strafing animation setup in Lyra was not built to support forward-facing locomotion. With these tweaks, now it supports both modes and we did this without writing a single line of code. Using the new tools mentioned in this blog, we could create a game where we use a strafing set while aiming, and forward-facing while exploring the world.
The changes we made are not destructive, and with the use of Linked Anim Layers, Anim Node Functions, and Property Access, we can reuse, replace, and compartmentalize our Animation Blueprint logic better than ever. Pose Warping and Distance Matching enable us to adapt animations to what our gameplay needs. Rewind Debugger enables us to debug our animation in context and with minimal setup.
These are only a few of the new features in Unreal Engine 5 that are built to empower animators and designers. New methods of Retargeting mean you could retarget Lyra both to and from your own characters, MetaHumans, or even Paragon heroes. You could try your hand at using the new experimental Motion Matching in Lyra.
With the release of 5.0, we welcome your feedback to improve animation in Unreal Engine 5. Join us in the forums, tell us what you think, and show us what you’re building next!
Get Unreal Engine today!
Get the world’s most open and advanced creation tool.
With every feature and full source code access included, Unreal Engine comes fully loaded out of the box.