Creating animation for your character

Characters wouldn't be very interesting without animations! In this recipe, we will cover the basic task of animating a character and exporting that animation to be played later in Sandbox.

Getting ready

There are four important steps involved in preparing and animating your character from CryENGINE 3:

  • Creating a character and export a .chr file
  • Entering the character's information into the .cba file
  • Animating the character and export a .caf file
  • Adding the exported .caf file to the character's .chrparams file

Use the SDK sample asset character to start this recipe, as the character creation process has already been discussed in previous sections.

How to do it...

First, let's open the character in the character editor:

  1. Open the character editor and open the Objects/Characters/neutral_male/sdk_character_male_v2.cdf. It is important to verify that your character is working in the engine before we can begin with animation.
  2. We will now open the animations.cba file, which can be opened in any text editor. You will find this file in the game/animations folder.
  3. In the CryENGINE SDK, the first entry is the sample character. You will notice that comments already exist to explain each of the parameters.
  4. If you are creating a custom character, then the best practice is to copy the definition for the sample character and set the Model File path, Animation path, and Database path.
    <AnimationDefinition>
    <!--the reference model-->
    <Model File="/../Objects/Characters/neutral_male/skeleton_character.chr"/>
    <!--the path with ALL animation we can use on this model-->
    <Animation Path="human_male"/>
    <!--for all animations use compression level 1-->
    <COMPRESSION value="2"/>
    <RotEpsilon value="0.0000001" />
    <PosEpsilon value="0.0000001" />
    <Database Path="human_male/human_male.dba"/>
    <!--for all animations need to detect footplants-->
    <FOOTPLANTS value="NO"/>
    <!--we apply the Locomotion_Locator modification just on BIP-files. Aliens, vehicles and weapons don't need it. -->
    <LOCOMOTION_LOCATOR value="YES"/>
    <!--we apply different modifications to the weapons . Human and Aliens don't need it. -->
    <!--a list of animation that need special handling-->
    <SpecialAnimsList>
    <!-- AIMPOSES COMMON -->
    <Animation APath="Aim" footplants="NO" compression="0" autocompression="0" SkipSaveToDatabase="1" />
    <Animation APath="vehicle" footplants="NO"/>
    </SpecialAnimsList>
    </AnimationDefinition>
    

Having verified that this character is already present in the .cba, we can begin animating. Should you be making a custom character, ensure your character is registered in the .cba before animation begins. Let's create a simple arm waving animation:

  1. To animate the character open the sample character Max file.
  2. Make sure that biped is not in figure mode as you will not be able to keyframe any bones.
    How to do it...
  3. As this is a 3ds max biped, you can now apply motion capture data to the live deforming skeleton.
  4. Set the animation mode in 3ds to Auto Key and move the right-hand bone into a wave position. You will notice that once you move the bone, a keyframe is automatically created.
  5. You may have to rotate the upper and lower arms to get a more realistic pose.
  6. Once you are happy with the position move the time slider to the tenth frame and set a different pose.
  7. Finally, as we want this animation to loop, we must set the last keyframe of our animation to the same position as the first keyframe.
  8. This can be done easily by selecting all the bones you want to animate by using shift + click on the keyframe in the timeline and dragging the copied keyframe to the final frame.
  9. In this example, copy the first keyframe to the twentieth frame.
  10. As we will only be exporting a single animation, we can set the time configuration in max to only show frames from 0 to 20.

    Note

    The exporter will automatically export the currently displayed frames in the animation time line, if not set otherwise.

  11. To export the animation, open the CryENGINE exporters in the tools tab and ensure that the skeleton_character has been added to the export nodes list.
  12. As discussed earlier, this will automatically add the parent node of the skeleton to the export bones list.
    How to do it...
  13. Clicking the export bones button will open the save dialog box, which allows you to save the animation as a .caf file.
  14. Save our waving animation under the defined path in the animations.cba for the character. In this case, save it as cookbook_wave.caf under the Animations/human_male folder.
  15. There is one final step that we must complete before being able to view our character animation in Sandbox's character editor. We must add this new animation to the characters animation list file .chrparams.
  16. Open the .chrparams file in any text editor and locate the animation list. It is defined by <AnimationList>:
    <AnimationList>
    <Animation name="#filepath" path="animationshuman_male"/>
    <Animation name="$AnimEventDatabase" path="animationshuman_malehuman_male.animevents"/>
    <Comment value="$Include = objectscharactershumanGlobalHuman.chrparams"/>
    Insert a new entry for our animation below the $Include line as below
    <AnimationList>
    <Animation name="#filepath" path="animationshuman_male"/>
    <Animation name="$AnimEventDatabase" path="animationshuman_malehuman_male.animevents"/>
    <Comment value="$Include = objectscharactershumanGlobalHuman.chrparams"/>
    <Animation name="Custom_cookbook_wave"path="cookbook_wave.caf"
    
  17. Having now added an entry in the .chrparams file, open Sandbox and then open the character editor.
  18. Using File | open, open the character Objects/Characters/neutral_male/sdk_character_male_v2.cdf.
  19. And notice in the left-hand side of the character editor that you can now browse into the newly created custom folder where you will see the cookbook_wave animation.
  20. Click on it to preview the animation.
    How to do it...
  21. You have now created and exported your animation to the CryENGINE!

How it works...

When a character is loaded by the engine, it checks for a .chrparams file that defines a list of valid animations for the particular character. These animations then become accessible through code, cut scenes, and the character editor to be played back.

In this example, we dealt with .caf animation data that is created by exporting the animation range from 3ds. Upon export the Resource Compiler is invoked and a certain amount of compression and optimization is applied to the animation to make it ready for real time playback.

There's more...

You may want more information on the compression of animations or how to expedite the character animation process by wildcarding animation names within the .chrparams file.

Changing the animations compression

You may have animations that are jerky or jittering. This can be caused by the original animation asset and in some cases, it can be caused by aggressive compression applied to the animation.cba.

The value to control compression is seen in a character's definition in the .cba as the line: <COMPRESSION value="2"/>.

Change this value to a lower number to compress the animation less aggressively.

.chrparams file Wildcard Mapping

Wildcarding the animation names within the .chrparams file can be carried out as follows:

  • Assigning each animation definition in the .chrparams file, line-by-line, can take an unacceptable amount of time and can lead to very big .chrparams files.
  • Wildcard Mapping uses the asterisk (*) to represent the filename. Using the asterisk in the in-game name will replace it with the part of the actual filename that is wildcarded.

    For example:

    <Animation name="coop_*" path="coopcoop_*.caf"/>.

  • The previous line will load all animation from the folder coop that starts with the word coop and has the extension .caf.
  • These animations will automatically be assigned an in-game name that starts with coop_ and then follows the part of the filename that comes after coop (which will be removed from the name).
  • A filename kickroundhouse.caf would be mapped to coop_roundhouse.caf.
  • It is important to ensure that these folders are kept clean of old and unused assets, so as not to waste extra memory.
  • One important advantage of using wildcards is that, once a folder is mapped then new animations can be quickly added to that folder without the need to add an animation definition in the .chrparams file each time.

    Note

    It is only necessary when the in-game name that is supposed to be assigned to the animation is substantially different than the filename of the .caf. Wildcard Mapping can even be used on an entire folder.

Animobject entity

A useful entity for testing animations is the animobject entity found under Entities | physics | animobject.

Once placed in a level, you can assign a model and then enter the string of the in-game animation name.

A good technique is to add this animobject to a flow graph and assign the animation to it using the Animation:PlayAnimation flow graph node.

Animobject entitycharacteranimation names, wildcarding

See also

  • To learn how to create a character refer to the Creating skinned characters for the CryENGINE recipe earlier in this chapter
  • To learn more on how to preview animation within the character editor, go to the next recipe in this chapter
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.255.250