CHAPTER 96: Bones (Patreon)
Content
CHAPTER 96: Bones
In Hollow Knight, the Knight had 12 animations. Walk, run, jump, fall, land, attack in four directions, dash, heal, and die. Twelve discrete states with instantaneous transitions between them. The Knight went from walking to jumping in one frame. From attacking to falling in one frame. There was no blending, no interpolation, no smooth transition. It worked because in 2D at 32 by 32 pixels, the instantaneous transitions were imperceptible.
CJ had 147 animations.
Walk. Run. Sprint. Walk tired. Run tired. Stop from walking. Stop from running. Stop from sprinting. Turn left while walking. Turn right while walking. Turn left while running. Turn right while running. Go up stairs. Go down stairs. Go up a slope. Go down a slope. Jump. Jump from running. Fall. Land soft. Land hard. Jump a fence. Climb a low wall. Swim. Drown.
Get into a car by the left door. Get into a car by the right door. Break the window and get in. Get out of a car. Get out of a car fast. Drive relaxed. Drive stressed.
Fire a pistol standing. Fire a pistol crouched. Fire a pistol from a car. Fire an AK standing. Fire a shotgun. Aim a sniper.
Punch. Punch combo. Kick. Block. Take frontal damage. Take lateral damage. Take rear damage. Die from a gunshot. Die from an explosion. Die from a fall. Die from being run over. Eat. Drink. Sit down. Smoke. And seventy more George hadn't yet enumerated.
A hundred forty-seven animations that had to transition smoothly between each other. CJ couldn't go from running to firing in one frame the way the Knight went from walking to attacking. A 3D human who changed posture instantly looked like a robot someone had turned off and on in a different pose. CJ needed blending: smooth transitions where the bones of his skeleton moved gradually from the posture of one animation to the posture of the next.
*
CJ was a skeleton with skin.
In the literal sense. The 3D model of CJ that Marcus was going to create was a mesh of triangles (the skin) that was linked to a hierarchy of bones (the skeleton). When a bone moved, the triangles linked to that bone moved with it. When the bone of the right arm rotated 90 degrees, the triangles of the right arm rotated 90 degrees. When the bone of the hip tilted, the entire torso tilted.
CJ's skeleton had 42 bones organized in a parent-child hierarchy. The root bone was the pelvis. From the pelvis came the legs (3 bones each: thigh, calf, foot) and the spine (3 bones: lumbar, thoracic, cervical). From the spine came the arms (3 bones each: humerus, forearm, hand) and the head (2 bones: neck and skull). From the hands came the fingers (simplified to 2 bones per finger: proximal and distal phalanx, with no middle phalanx because the detail was invisible at game distance). And the skeleton had auxiliary bones for the shoulders, the clavicles, and the kneecaps that controlled how the mesh deformed at the joints.
Kenji, the 3D tutor, designed the skeleton with the experience of someone who had rigged characters for Pixar. Each joint had rotation constraints that prevented the bones from moving in impossible directions: the elbow couldn't bend forward, the knee couldn't rotate laterally, the neck couldn't rotate 180 degrees. The constraints were what separated a functional skeleton from one that produced the visual aberrations the players called "spaghetti glitches": limbs that twisted at impossible angles because the animation system let them go where the anatomy didn't allow.
*
George implemented the animation system with three-layer blending.
The first layer was the base animation: the main pose of the body. Walk, run, stand, sit. The base animation controlled all the bones of the skeleton and defined the overall posture.
The second layer was the partial override: an animation that controlled only some bones, superimposed on the base animation. CJ could walk (layer 1: legs moving) and at the same time aim a pistol (layer 2: arms and torso oriented toward the target). The two layers blended: the lower part of the body executed the walk animation and the upper part executed the aim animation. The result was a character who walked and aimed at the same time, which was impossible with a single layer of animation because you would have needed a separate animation for "walk-and-aim-left," "walk-and-aim-right," "run-and-aim-up," and every other combination.
The third layer was the additive: animations that added to the other layers without replacing them. CJ breathed (the rib cage expanded and contracted in a 90-frame cycle) independently of what he was doing. CJ blinked every 3-5 seconds. CJ moved his head to look at points of interest. These animations were subtle and continuous, they never stopped, and they gave CJ the illusion of being alive even when the player wasn't pressing any button.
The blending between base animations was done with linear interpolation of the rotations of each bone. When CJ transitioned from walking to running, each of the 42 bones of his skeleton moved gradually from the rotation it had in the walk pose to the rotation it had in the run pose. The transition lasted 6 frames (200 milliseconds), which was fast enough for CJ to respond to the player's input with no perceptible delay and slow enough for the movement to look fluid instead of an instantaneous change of pose.
George calibrated the blend time for each transition individually. Walk to run: 6 frames. Run to sprint: 4 frames (faster because the urgency of sprinting had to feel immediate). Run to stop: 10 frames (gradual braking with visible inertia). Walk to fire: 3 frames (the response of the combat had to be instantaneous). Stop to sit: 15 frames (because sitting was a voluntary and deliberate action that needed no urgency).
Each transition was an equation between responsiveness and realism. Fast transitions made CJ respond to the input like a game character: immediate, precise, obedient. Slow transitions made CJ move like a person: gradual, with weight, with inertia. The sweet spot was different for each pair of animations, and George found it the same way he had found the 3 frames of Hollow Knight's parry: testing, adjusting, testing again.
*
When CJ died, he stopped being an animated character and became a physical object.
George implemented ragdoll physics: the system that turned CJ's skeleton into a chain of rigid bodies connected by joints with constraints. Each bone became a body with mass, and each joint became a pivot point with rotation limits. The result was a body that fell according to gravity and that collided with the environment in ways that weren't animated but simulated.
The ragdoll activated in three situations: death, fall from a great height, and explosion.
When CJ died from a gunshot, the ragdoll activated with an initial impulse that corresponded to the direction of the shot. A frontal shot pushed the body backward. A lateral shot turned it. A shot to the head tilted it to one side. The body fell to the ground with the physics of a sack of bones that no longer has muscles to hold it up: the arms opened, the legs bent, the head hung. Each death was unique because the initial conditions (the position of the body, the direction of the impulse, the geometry of the environment) were different every time.
The falls from a great height produced ragdoll on impact. CJ could fall from a building (the damage system calculated the damage according to the height: more than 10 meters was lethal) and his body bounced against the ground, the steps, the parked cars, whatever was below. The bounce was damped: George added a restitution factor of 0.2, which meant the body lost 80% of its energy on each impact and settled quickly instead of bouncing like a ball.
The explosions were the most spectacular. The ragdoll activated with a radial impulse from the center of the explosion. CJ went flying in the direction opposite the point of detonation, spinning in the air with the rotation the impulse gave him, and landed several meters away with a series of damped bounces. The NPCs that died in explosions also used ragdoll, which produced scenes where three or four bodies went flying simultaneously in different directions from the same point, each with its own trajectory and its own sequence of bounces.
Marcus saw the ragdoll working and said something George didn't expect:
"It's funny."
"Funny?"
"An NPC that dies with a death animation looks sad. It falls in a predictable way, always the same, like an actor performing his last scene. An NPC that dies with ragdoll looks funny because it falls in absurd ways: the legs up, an arm caught on a fence, the head bouncing against a staircase. It's real physics applied to a human body and the result is involuntary comedy."
"Is it a problem?"
"No. It's perfect for Los Santos. This game has humor. Big Smoke orders food at a drive-thru during a chase. Ryder insults everyone. The talk radio is satire. The ragdoll is another kind of humor: the humor of physics. Not planned. Not written. Emergent. And the emergent is always funnier than the written because no one saw it coming."
George left the ragdoll as it was. The NPCs died with physics. And sometimes they died in ways that made the testing team laugh, which was a form of QA Tomás didn't have in his red notebook but that was just as valid.
*
Inverse Kinematics was the technique that made CJ exist in the world instead of floating over it.
Without IK, CJ's feet followed the walk animation regardless of the geometry of the ground. If CJ walked up a staircase, his feet sank into the steps or floated over them because the walk animation assumed flat ground and the steps weren't flat. If CJ stood on a slope, one foot was in the air and the other passed through the ground. The character looked disconnected from the world: a ghost that moved over the surface without touching it.
George implemented IK for CJ's legs. The system cast two vertical raycasts from CJ's hips downward, one for each leg. The raycasts detected the height of the ground beneath each foot. If the ground was higher than where the animation placed the foot (step, curb), the IK raised the leg so the foot landed on the surface. If the ground was lower (gap, downward slope), the IK extended the leg so the foot reached the ground.
The adjustment was in real time, every frame, for both feet simultaneously. And the IK didn't just move the feet: it recalculated the whole chain of the leg. Moving the foot changed the angle of the knee, which changed the angle of the hip, which tilted the pelvis, which affected the spine. The result was that when CJ went up a staircase, his whole body adapted: the legs lifted higher, the knees bent more, the hip tilted with each step, and the torso adjusted to keep balance.
Daniel optimized the IK for PS2 with the simplest possible solution: on PS2, the IK only applied to the player's character. The NPCs had no IK. Their feet floated over the steps and sank into the slopes. At the distance most NPCs were seen on PS2 (more than 5 meters), the error was invisible. But CJ, who was always in the foreground, always 3 meters from the camera, needed feet that touched the ground.
"On PC all the NPCs within 20 meters have IK," George said. "On Xbox, within 10. On PS2, only CJ."
"If anyone notices that an NPC 15 meters away floats over a step on PS2, they have eagle eyes and too much free time," Daniel said.
*
At the end of August, George integrated the skeletal animation, the three-layer blending, the ragdoll, and the IK into a test character that was CJ in the form of a gray mannequin.
The mannequin walked down Grove Street. The feet touched the ground thanks to the IK: when he went up the curb of the sidewalk, the left leg lifted higher than the right and the hip tilted two degrees. When he walked over the grass of the yard of CJ's house, the feet sank slightly because the grass was modeled as a surface lower than the sidewalk.
George pressed run. The mannequin transitioned from walking to running in 6 frames, the 42 bones of the skeleton interpolating smoothly from one pose to the other. The arms swung faster. The strides lengthened. The body leaned forward.
George pressed sprint. A 4-frame transition. The mannequin launched forward with the urgency of someone fleeing or pursuing. The arms pumped. The legs were pistons. The additive breathing accelerated from a 90-frame cycle to a 45-frame one.
George released everything. The mannequin braked in 10 frames, the feet dragging slightly from the inertia, the torso leaning back as compensation. It stopped. It stood. Breathing. Blinking. The head turning slightly to look at a point of interest George had placed to the right: a parked car.
George drew a placeholder pistol. Layer 2 activated: the arms and the torso transitioned to the aim pose in 3 frames while the legs stayed in the standing pose. The mannequin was standing and aiming. George walked while aiming: the legs executed the walk animation while the torso kept the orientation of the weapon. Two layers of animation blending in a single body.
George fired at the parked car. The weapon's recoil was applied as an additive animation of 4 frames that shook the arms without affecting the legs. Then George threw the mannequin off a 3-meter wall. The mannequin fell, landed with the hard-landing animation (knees bending deeply, hands touching the ground), and got up.
Then George threw the mannequin off a 15-meter wall. The ragdoll activated on impact. The gray mannequin collapsed against the ground, the arms opening, the legs bending at angles the animation would never produce because they were the result of physics acting on a body with no muscular control. The mannequin rolled twice from the inertia of the impact and stopped in a position no animator would have designed but that was perfectly correct according to Newton's laws.
Elena, who was watching from her desk, came over.
"It's a person," Elena said.
"It's a gray mannequin."
"It's a gray person. It moves like a person. It breathes like a person. It walks up the stairs like a person. It falls like a person. It's ugly and it has no face or clothes or hair. But it's a person. I can see it."
It was the compliment George needed to hear. Because if Elena, who had spent three years designing spaces where characters lived, could see a person in a gray mannequin that walked down a street of cubes, it meant the animation system worked. It produced the most important illusion in the game: that what was on the screen was alive.
Marcus was going to give that person a face, clothes, hair, and the visual identity of CJ. The writer was going to give him a voice and a story. Lena was going to give him the sound of his footsteps and the noise of the city around him. But the life was there before all of that. The life was in the 42 bones that moved with three-layer blending and in the feet that touched the ground thanks to two raycasts that measured the height of the world beneath them.
End of Chapter 96