Die
The die ability will play a death animation when the character dies. The death animation is determined by the hit location that causes the character to die. If for example an arrow kills the player after hitting them in the chest the death animation should play a falling backwards animation. The die ability includes a forward and backwards death animation but the ability can easily be extended for other death types.
Setup
- Select the + button in the ability list under the “Abilities” foldout of the Ultimate Character Locomotion component.
- Add the Die ability. This ability should be positioned near the top of the list so it will override any abilities beneath it.
- No extra setup is required – when the character dies the ability will automatically start.
Adding New Death Animations
There are two steps required in order to new death animations:
- The ability needs to detect which animation should be played.
- The Animator Controller needs to have the new animations added to it.
Ability
When adding new functionality we recommend subclassing the abilities so it’s easier to update when a new version of the Ultimate Character Controller is released. For this situation you’ll want to subclass the Die ability:
using Opsive.UltimateCharacterController.Character.Abilities; public class MyDieAbility : Die { }
When the ability starts it will call GetDeathTypeIndex to determine the AbilityIntData Animator parameter value. Your custom die ability should override this method and return a new value. In this example we will return a value of 3 if the force is greater then 10:
using Opsive.UltimateCharacterController.Character.Abilities; public class MyDieAbility : Die { /// <summary> /// Returns the value that the AbilityIntData parameter should be set to. /// </summary> /// <param name="position">The position of the force.</param> /// <param name="force">The amount of force which killed the character.</param> /// <param name="attacker">The GameObject that killed the character.</param> /// <returns>The value that the AbilityIntData parameter should be set to.</returns> protected override int GetDeathTypeIndex(Vector3 position, Vector3 force, GameObject attacker) { if (force.magnitude > 10) { return 3; } return base.GetDeathTypeIndex(); } }
Animator
Now that the custom ability has been created it is time to modify the Animator Controller so the death animation with a type of 3 can play. This can be done by creating a new state within the Full Body Layer -> Die substate and transitioning to it when the AbilityIntData parameter value is equal to 3:
Inspected Fields
Camera Rotational Force
The amount of force to add to the camera when the character dies. This value will be multiplied by the magnitude of the force that killed the character.