Tutorial 6 - Death Animations

Tutorial 6 - Death Animations

When a character dies he will automatically be ragdollized immediately. The ragdoll will stop all animations on the character. This is the default behaviour. In some projects the visual style requires to play a death animation before the ragdoll is triggered. This article will explain how to implement these into CryENGINE 3.

There are multiple ways of achieving this. This article will be based upon the principle of triggering the ragdoll from the AnimationGraph instead of the LUA script after the death animation has been played.

Step 1: LUA Script

The code that is being executed when a character dies can be found in BasicActor.lua. The player and all human AI are derived from this file. The file can be found here: Game/Scripts/Entits/actor/BasicActor.lua

Find the following lines in the function function BasicActor:Kill(ragdoll, shooterId, weaponId, freeze)

elseif (not self:IsOnVehicle()) then
     if (ragdoll) then
           self:TurnRagdoll(1);
     end
end

Comment out the line with the TurnRagdoll command. Since the health will still be set to zero, the AnimationGraph will choose the Dead state automatically and trigger the ragdoll behaviour.

To trigger a death animation before this happens, send a Signal to the AnimationGraph:

self.actor:SetAnimationInput("Signal", "playDeathAnim");

This change does not interfere with the Ragdollizing upon Fall & Play.

Step 2: AnimationGraph Setup

The AnimationGraph View "Dead" holds the Dead state. This state has a Modifier attached to it which also triggers the character to turn into a ragdoll. Since the LUA script already triggers this behaviour the re-triggering in the graph has no effect. However, when using death animations, it becomes necessary.

Only the graph can know when the character should turn to ragdoll, after it has finished playing the death animations. The LUA script is setting the Signal input to the value playDeathAnim. To play a death animation a new state must be added to the graph that reacts to this input.

This state does not need to have the "TurnRagdoll" Modifier attached, as it will automatically transition into the "Dead" state once it has finished. But it must have similar or the same selection criteria as the Dead state itself (depending on your setup), as the health value will still be set to 0 for example. But it must additionally specify the Signal input as it is being sent from LUA.

As with all signaled inputs, the state must be built upon the "OneShot" parameter preset. Set up the animation and the blending time on this state. For fine-tuning, use the time slider to determine when to blend over to the next state and thereby triggering the ragdoll.

To avoid the physics or any other system from moving the dying character and causing it to slide while playing the death animation, the movement control method should be set to Animation for both horizontal and vertical. If the death animation contains movement, then AnimatinHCollision mightbe a good choice, or alternatively Entity with the XY Movement and Rotation being extracted from the animation.

Tip

Depending on how your character dies or which direction he was hit from it might make sense to set up different death animation signals. It is also possible to use the randomizer of the animation graph to choose a random animation from a list.