What is Physics-Based Character Animation in games? — Using Unreal Engine approach as an example

Ray Liao
10 min readJan 24, 2024

--

With the launch of Party Animals, physics-based character animation has once again been brought to the public’s attention, providing players with a fun and surprising gameplay experience.

Party Animals

What is Physics-Based Character Animation?

Traditionally, character animation in games is often processed through keyframe animation and state logic, which cannot interact well in complex environments and may even cause problems such as clipping. Physics-Based Character Animation (or Active Ragdoll) is a programmatic animation method that combines keyframe animation with ragdoll physics. In principle, it involves configuring ragdoll physics simulation (rigid body + joint constraints) for characters and making the rigid body and joint constraints follow the motion of keyframe animation as required. Therefore, it can achieve animation semantics for the current state of the character while also interacting with the game world.

  1. Make game fun
Gang beasts
Human fall flat

2. Increase the quality and realistic of animation

Uncharted
The last of us

3. Increase player immersion

The Elder Scrolls VR Mod

Additionally, in some places, character physics animation refers to driving characters through joints using physics, which means that controllers are constructed to control the joint torque of characters, making them produce the desired movements. DeepMimic is one of the representatives of this method. This technique referred to in our article is different (the biggest difference is that the physics animation in our article must have a keyframe animation as a reference). You can refer to other articles for more information.

Basic theory

Ragdoll physics simulation

The main theory of physics animation is related to ragdoll physics. The ragdoll physics system was originally mainly used in scenes of character death and injury (starting with Jurassic Park: Trespasser in 1998). When the character dies, the physics situation is simulated for animation. Currently, most ragdoll physics are mainly implemented based on multiple rigid bodies and corresponding constraints. The rigid body is often corresponding to the character’s skeleton, and the rigid bodies are connected through constraints.

Rigid body

Rigid body refers to an solid object that is rigid, which does not deform under external forces. Therefore, fluids, elastic materials, and plastic materials are not rigid bodies. Generally, a rigid body has six degrees of freedom: three rotations (pitch, yaw, and roll) and three translations (x, y, and z).

Joint constraint

Generally , constraints are used to limit the freedom of rigid bodies, including collision contacts, friction, springs, pulleys, and so on. Joint constraint is a special type of constraint that is a constraint between two rigid bodies, which can simulate door hinges, ropes, biological joints, etc. The theory of this part can refer to PhysX’s Joints (many game engines such as UE and Unity have used or are using Nvidia Physx as a physics solution, although UE5 replaced from PhysX to Chaos, most parts remain the same). Constraint component in Unreal is d6 joints, which can freely lock, limit, or release three dimensions of displacement and three dimensions of rotation. By limiting, you can achieve the examples of Joint in PhysX below.

examples of Joint in PhysX

In ragdoll simulation, joint constraints are usually used to prevent characters’ joints from rotating too much during the simulation. Generally, joint restrictions for various parts of the human body are simulated to make the ragdoll more realistic.

For convenience, we will use the term ‘constraint’ to refer to joint constraints in the following text, although these two concepts are different.

Combining keyframe animation and ragdoll physics

There are many methods can be used to drive our ragdoll to a specific animation target. We will mainly look at the Unreal’s physics animation solution: Physics Control (UE 5.3 version). To drive the ragdoll to a specific animation pose, it can be simply understood as driving the rigid body and corresponding constraints. This can be achieved through the linear drive and the angular drive in the constraint. In PhysX, the force applied by the motor can be abstracted into the following formula.

force = spring * (targetPosition — position) + damping * (targetVelocity — velocity)

There are two modes of angular drive: twist and swing, and SLERP (spherical linear interpolation). The difference between these two modes is how to estimate the path from the current orientation to the target orientation (or how to interpolate). In twist and swing mode, the rotation is decomposed into twist and swing components, which are used to achieve interpolation. This mode is more intuitive than SLERP, but when it drives, for example, 180 degrees of swing, the drive will not interpolate the shortest arc path. Howerver, SLERP uses quaternions, so it can find the shortest arc path between the current and target orientations.

The following figure explains the two ways of angular motor (from Ming-Lun Chou in Naughty Dog) you can also read his post to learn more.https://www.gamedev.net/forums/topic/696882-swing-twist-interpolation-sterp-an-alternative-to-slerp/

Twist and swing decomposition:

The diference of interpolation:

In UE5 Physics control, angular drive used SLERP mode. We can see how they initialize joint constraint by reading the source code:

FConstraintInstance* FPhysicsControlRecord::CreateConstraint(UObject* ConstraintDebugOwner, FName ControlName)
{
``````

FBodyInstance* ParentBody = UE::PhysicsControlComponent::GetBodyInstance(
PhysicsControl.ParentMeshComponent, PhysicsControl.ParentBoneName);
FBodyInstance* ChildBody = UE::PhysicsControlComponent::GetBodyInstance(
PhysicsControl.ChildMeshComponent, PhysicsControl.ChildBoneName);

``````

ConstraintInstance->InitConstraint(ChildBody, ParentBody, 1.0f, ConstraintDebugOwner);

// Ensure the control point is set
UpdateConstraintControlPoint();

ConstraintInstance->SetLinearXMotion(ELinearConstraintMotion::LCM_Free);
ConstraintInstance->SetLinearYMotion(ELinearConstraintMotion::LCM_Free);
ConstraintInstance->SetLinearZMotion(ELinearConstraintMotion::LCM_Free);
ConstraintInstance->SetAngularSwing1Motion(EAngularConstraintMotion::ACM_Free);
ConstraintInstance->SetAngularSwing2Motion(EAngularConstraintMotion::ACM_Free);
ConstraintInstance->SetAngularTwistMotion(EAngularConstraintMotion::ACM_Free);

ConstraintInstance->SetLinearPositionDrive(true, true, true);
ConstraintInstance->SetLinearVelocityDrive(true, true, true);
ConstraintInstance->SetAngularDriveMode(EAngularDriveMode::SLERP);
ConstraintInstance->SetOrientationDriveSLERP(true);
ConstraintInstance->SetAngularVelocityDriveSLERP(true);

ConstraintInstance->SetDisableCollision(PhysicsControl.ControlSettings.bDisableCollision);

return ConstraintInstance;
}

Therefore, for making ragdoll physics to follow keyframe animation, Physics control will drive each joint constraint to target animation pose in every tick. This drive is achieved by setting the target position and linear velocity of the linear drive, as well as the target orientation and angular velocity of the angle drive. Below source code showed how they do:

void FPhysicsControlComponentImpl::ApplyControl(FPhysicsControlRecord& Record)
{
······

// Set strengths etc
if (ApplyControlStrengths(Record, ConstraintInstance))
{
FTransform TargetTM;
FVector TargetVelocity;
FVector TargetAngularVelocity;
CalculateControlTargetData(TargetTM, TargetVelocity, TargetAngularVelocity, Record, true);

ConstraintInstance->SetLinearPositionTarget(TargetTM.GetTranslation());
ConstraintInstance->SetAngularOrientationTarget(TargetTM.GetRotation());
ConstraintInstance->SetLinearVelocityTarget(TargetVelocity);
ConstraintInstance->SetAngularVelocityTarget(TargetAngularVelocity / UE_TWO_PI); // In rev/sec

if (ParentBodyInstance)
{
ParentBodyInstance->WakeInstance();
}
if (ChildBodyInstance)
{
ChildBodyInstance->WakeInstance();
}
}
}

In addition, Physics Control provides driving control for world space and parent space. The key difference is whether each parent joint is considered when driving to the pose target. As below figure. The left side is the physical animation controlled by world space, and the right side is by parent space. When they are hit by a cube, the feedbacks are different. Each joint in world space will be independently driven to the animation target (the red transparent person is the original animation pose as a reference). Different joints can choose different spaces and can be freely matched, which is related to the usage scenario. This will be discussed in detail later.

Other implementation solutions.

There are many solutions of physical animation shared online. They are very similar to Unreal’s solution. Learning their experiences very helpful for us to create physical animtion in Unreal.

Physics Animation in Uncharted 4 by Naughty Dog in GDC 2017:

Abstracted into two drive methods, although different from the UE physics engine (which uses Havok), the implementation and details are somewhat different, but the way required for simulation effects in some scenarios is very similar. https://www.youtube.com/watch?v=7S-_vuoKgR4

The author provided pseudocode for Keyframe controller. Literally, it sets linear velocity, but how to interpolate velocity is related to position, acceleration, etc.

Physical Animation in Star Wars Jedi by Respawn Entertainment in GDC 2020:

The methodology was abtracte as three methods, and used in different scenarios. Watch this video to learn more:

In the climbing suspension beam case, the author used a velocity drive, which can provide stable movement performance. The author also provided pseudocode that considers position factors when interpolating velocity.

There is another sharing about physical animation by EA in GDC 2018. Compared with the previous two sharings, they focus more on the physical animation cases used in sport games. I will summarize this article when I have time. https://www.gdcvault.com/play/1025210/Physics-Driven-Ragdolls-and-Animation

Parameters in Physics control

Control

There are some parameters were exposed to user for adjusting in physics control. They are same meaning no matter in world space or parent space.

We can set up physical animation for character in a second by connecting ‘ Create Controls and Body Modifiers from Limb Bones’.

Body Modifiers

here is a concept called Body Modifiers in Physics Control, which provided more intuitively and conveniently adjust the physical simulation parameters of various physical bodies. For example, it can control the gravity state of a certain joint of a character, whether to enable physical simulation, and the blending weight with animation. Through this, we can use the world space control and parent space control to achieve various physical animation effects through this component interface.

  1. Set Body Modifier Collision Type

Decide body whether turn on collison

2. Set Body Modifier Gravity Multiplier

0 is no gravity. 1 is normal gravity. It will be set to 1 when ragdoll.

3. Set Body Modifier Kinematic Target

Set body target location and orientation independently. When drving body to animation pose, they used this function to drive every body.

4. Set Body Modifier Movement Type

Contains three status: static/kinematic/simulated,static mean maintain initial status of body without driving to animation and simulating physics; keyframe means totally follow animaiton target pose (the body will turn off collision automatically ); simulated means combining animation drive and physics simulation.

5. Set Body Modifier Physics Blend Weight

The blend weight of target animation and physics simulation. Star wars in GDC shared a lot a cases of applying blend weight.

6. Set Body Modifier Update Kinematic from simulation

Control body wheter update kinematic target from simulation

7. Set Body Modifier Use Skeletal Animation

Control body whether to use skeletal animation as drive target.

In addition, the above interfaces also expose batch setting interfaces, which can be used to control multiple parts cleanly. (The source code only does ‘For Each’ execution.)

More usages

Physics Control not only controls character physical animation, but also controls the motion relationship of a physical body relative to another. Character physical animation is only one of its applications (It’s a complex one, composed of many control relationships). Unreal has updated a video on its channel that demonstrates the interaction with a dog through Physics Control, which showcases many good examples. For example, the hand can also be controlled to retrieve a stick through Physics Control. https://www.youtube.com/watch?v=FK7FBBdY5fY

I have been following UE’s development in this area for a long time, from the earliest Physical Animation to the first version of Physics Control updated in 5.1. I have seen Epic constantly improving and abstracting the top layer to make it easy to understand, and trying to avoid users from doing too many complex configuration operations. They also continue to iterate on the Content Examples, which has given us a lot of learning resources. Although Physics Control is still an experimental plugin in UE5.3, it is not far from release status.

Unfortunately, it still needed a lot of time to adjust for achieving the appropriate effects, which is a bit inefficient. The differences between different cases are also very large (such as sliding and climbing are very different scenes). We can only hope that the academic community can truly develop an industrial-level physical animation solution that uses force-driven simulations of human joints to create animation movements, and then using machine learning to produce qualified animations. Only by truly simulating the joint physical motion method can we achieve the ultimate solution. This is probably the vision of articles like DeepMimic.

Conclusion

Using Physics Control, by configuring the detailed parameters of each joint of the character (including physical assets, Control, Body Modifiers), we can achieve any ideal physical animation. I will update an article on my own practical experience later, with the following table of contents:

  1. Basic steps to configure Physics Control
  2. How to configure character physical assets (collision body/joint constraints)
  3. How to acheive some official/classic case
  4. How to achieve physical animation like Party Game
  5. More applications?

Feel free to discuss with me at any time!

--

--