Networked Locomotion System using Root Motion
Overview Author: In this tutorial, you will learn how to make a root motion based animation blueprint to work with multiplayer games. You will learn how to: Replicate two events which are setting t...
Overview
Author:
In this tutorial, you will learn how to make a root motion based animation blueprint to work with multiplayer games.
You will learn how to:
- Replicate two events which are setting two variables to two axis values.
- Use those variables for a blendspace.
- Get references to those variables in the animation blueprint.
In this tutorial, we will be using the Movement Animset Pro made by Kubold.
Requirements
You must have a basic blueprint networking knowledge and you must know the basics of animations. You also need to know what root motion is and how to use it.
Getting Started
Retargeting Kubold's Animations to your A-Pose Mannequin skeleton
Kubold's animations from Movement Animset Pro are made on a T-Pose skeleton which is the default mannequin, but in newer versions of Unreal Engine 4, the standard UE4 mannequin is standing in A-Pose. If you retarget your animations from the T-Pose skeleton to the A-Pose skeleton, you might get some bad results. To fix this, you need to open the T-Pose skeleton, open the retarget manager, hide the current pose (which should be the T-Pose) and now, you will get an A-Pose skeleton. To use it, just select the option called Use Current Pose.
1. Open the retarget manager.
2. Hide the Current Pose.
3. Use Current Pose.
4. Open your Character Blueprint and enable Use Controller Rotation Yaw and set the camera boom's Use Pawn Control Rotation to true. After that, attach the camera boom to the head bone of your character mesh.
Retargeting the needed animations
1. Select the blendspace included in the Movement Animset Pro.
2. Right click and select Duplicate Anim Assets and Retarget.
3. Retarget the blendspace animations to another folder (optional).
Editing the Animation Blueprint
1. Open the Animation Blueprint provided in the Third Person Template or your own Animation Blueprint.
2. Create two floats (variables) called "MoveForward" and "MoveRight".
3. Open the Default state machine located in the anim graph. Then, open the Idle/Run state and switch the blendspace found there with the one provided by Kubold. After that, plug in the created variables into the blendpace pins.
Editing the Character Blueprint and making more changes to the Animation Blueprint
After setting-up our Animation Blueprint, it is time to move to editing the Character Blueprint.
Creating and setting-up two variables (floats) in our Character Blueprint
1. Create two variables (floats) called MoveForward and MoveRight. Make sure they are set to Replicated.
2. Now, create two custom events. One is called MoveForward_RPC and one is called MoveRight_RPC. Make sure they are both Server RPCs (make sure they are set to Run On Server) and they need to be reliable. Then, add one input pin for each of the events. The input pins should be floats and their name should be MoveForward and MoveRight.
3. Look for the axis events called "MoveForward" and "MoveRight" and call the two custom events from them setting the input pins of the events to the axis values of the axis events.
Back to the Animation Blueprint
After making these changes to the character blueprint, go back to the Animation Blueprint and get a reference to our character, then follow the next steps.
Now, you need to follow all my last steps.
1. Move Forward Code.
2. Move Right Code
Sprinting
To be able to run, you need to create an action event called Sprint, set the key to Left Shift, make 3 custom events (2 of them are replicated), make a replicated variable and repeat the above two steps, but with two different values.
1. Create an action event called Sprint.
2. Create 3 custom events. The first one should be set to Multicast and it should be enabled. Call it "Sprint". The second one shouldn't be replicated. Call it "UpdateSprint". The third one should be set to RunOnServer and it should be reliable. Call it "ClientUpdateSprint". All the three events should have a bool input pin called "Is Running?". Also, make sure to create a replicated variable which is a bool called "bIsRunning?". From the first event, set the bIsRunning? bool to the custom event's bool input pin. Call the first event from the second one connecting their input pins and then, call the second one from the third one, connecting their pins.
3. Look for your action event called Sprint and drag it into the graph. Then add a "SwitchHasAuthority" node to the Pressed exec and call the second event from the authority and call the third event from the remote. Set the input pins to true. Do the same thing for the Released exec, but set the input pins to false.
Changes to the Animation Blueprint
Finally, we need to go back into the animation blueprint, copy and paste the Move Forward Code and the Move Right code, but set the Targets of the FInterp Constant nodes to 1 and -1 instead of 0.6 and -0.6. Then, we will just add a branch at the beginning with the bool variable located into our character. To do this, we need to get these variables from the character and make new variables into the animation blueprint which are set the the variables located in our character.
1. Copy and Paste the Move Forward and the Move Right code, but set the targets of the FInterp Constant nodes to -1 instead of -0.6 and 1 instead of 0.6.
2. Add a branch at the beginning of the two sequences with the condition being the bIsRunning? variable. True goes to the second sequence and false goes into the first sequence.
3. Enjoy your root motion networked locomotion system!