MayaCE3 Tutorial 3: Replacing the player model with a custom character
This tutorial will show you how to replace the player model with an entirely new custom character with its own custom key-framed animations. Brace yourself, things will be more technical than the previous tutorials. We’ll only deal with the model in a third-person view (camera over the shoulder).
So I have in my scenes a bunch of animations ready to be used (move forward, left, right, back, etc…). As explained in the previous tutorial I have exported and checked them in the character Editor.
Note: Since we’re going to replace the player model, don’t forget to add a weapon joint called “weapon_bone” to your character’s skeleton (as a child of the right hand’s joint).
1) Create a .cdf file for your character:
This is easy. Just load your .chr file in the Character Editor and simply do a File->Save As. This will save it as a .cdf file (which itself refers to the .chr file). This is necessary because many functions we’re going to use only deal with .cdf files.
2) Create a Locomotion Group:
We’re going to start by creating a locomotion group. First, open the Locomotion Group Editor:
Then go to File->Load Character:
If everything goes well, you should see the list of available animations on the left-hand side.
Now we’re going to drag and drop our animations in the relevant slot, like so:
If there is a red square instead of a green one, hover your mouse over it and you’ll get some information about the problem.
You can test how the animations blend together by clicking on the “Locomotion Preview” tab and moving the joystick cursor (in the “Test” tab) around. If you see some weird scaling or deformations it means you should troubleshoot the animations individually in the Character Editor. Or maybe you dragged an animation to the wrong slot.
Finally, save the locomotion group. In this case I saved it as “run_relaxed” in …\Game\Animations\my_objects\mouse\LMG.
3) Add the Locomotion Group to the .chrparams:
Now we need to add manually the LMG to the list of animations in the character’s .chrparams (located in this case in: …\Game\Objects\my_objects\mouse).
Note: The locomotion group can be considered itself as an “animation”, even though it in fact calls a bunch of existing animations.
4) Define the IK handles:
In order to benefit from the cool procedural IK behaviors of the CryEngine (legs and feet adapting automatically to the ground plane to avoid intersection) we have to define the IK handles. We also do this in the .chrparams file by adding a block of code within the Params element:
<IK EndEffector=”Bip01 R Hand” Handle=”RgtArm01″ Root=”Bip01 R UpperArm” Solver=”2BIK”/>
<IK EndEffector=”Bip01 L Hand” Handle=”LftArm01″ Root=”Bip01 L UpperArm” Solver=”2BIK”/>
<IK EndEffector=”Bip01 R Foot” Handle=”RgtLeg01″ Root=”Bip01 R Thigh” Solver=”2BIK”/>
<IK EndEffector=”Bip01 L Foot” Handle=”LftLeg01″ Root=”Bip01 L Thigh” Solver=”2BIK”/>
<IK EndEffector=”Bip01 Neck” Handle=”Spine_SpineToNeck” Root=”Bip01 Spine” Solver=”CCDX” fStepSize=”10″ fThreshold=”10″ nMaxInteration=”15″/>
Pay attention to the names of EndEffector and Root here; they need to match your character’ skeleton joints exactly!
5) Create an Animation Graph:
To create an animation graph from scratch can be very a very daunting task. Which is why we’re going to use an already existing one… Thankfully, the good people at Crytek have forgotten an unused graph file which will work fine for our purpose. Open the Animation Graph and load the graph called “GirlTest.xml”.
It will complain that the character it refers to doesn’t exist, just click OK.
The first thing to do is to tell the graph to use our character. To do so, go to View->Preview Options.
This will bring up a panel to the right where you can substitute your character:
Next click on Locomotion (in the Views palette). This will show the locomotion diagram (we only care about Walk, Run and Idle). Then click on Walk (or Run) and input you locomotion graph name into the Animation Name field:
You’ll have to do the same thing for both the Walk and Run nodes. Do it also for the Idle node, although you’ll notice that for that one a random modifier is in effect. Click on the Randomizer button next to the animation name and replace all the animation fields in the popup window by your Idle animations. Or if you don’t care for the randomizer, just input the name of your Idle animation intead of “<RandomSet:…>”.
Don’t forget to save the animation graph as the name of your character (I called it “mouse.xml”) alongside the other graph files in …/Game/Animations/Graph.
6) Replace the player model:
To replace the player model, we’ll need to tweak the text file called “player.lua” located in …\Game\Scripts\Entities\actor. Replace the AnimationGraph and UpperBodyGraph with the anim graph you just created.
In the Properties section of the file, change the fileModel and clientFileModel to point to your .cdf file.
Note: You HAVE to use the .cdf file, NOT the .chr file!
This will make sure the third-person model and the shadow are those of your model. You may want to also change the first-person models, but this is beyond the scope of this tutorial.
Incidentally you can also tweak the speed values to better match the speed of your animations:
You can also place the camera slightly to the side of the character, so we don’t just stand right behind it:
In this case, I have moved the camera 1 meter to the right of the character (in X).
Finally, launch Sandbox (or close it first if it was open) and press CTRL+g to jump in-game. Then press F1 to switch to third-person view and take you character out for a walk…
You might want to use this console command:
It’ll draw a green line for the direction of your character and a yellow one for the speed.
And that’s it. Let me know if you have any question…