At this point we have three files. A material (baseball_bat.mtl), a third person geometry file (baseball_bat_tp.cgf) and a first person character file (baseball_bat_fp.chr). It’s not enough to get a weapon into the engine. But to test that it’s working (and we should at this point) we could drag the CGF file into a map as level-geometry. To test the CHR file, use the Character Editor. Make sure everything is on the correct axis (and, for instance loading.) You should not see arms, just the weapon. (And if you enable the display of joints in the Debug Settings, you should see the arm skeleton.
To get CryEngine to treat these as weapons, we need to write a couple of script files. One is a chrParam file, it’s simply an XML file which tells the skeleton where to find animations. They can be a little complicated to set up, but not for something this simple. Melee weapons only need a few animations, that’s all. So this is a rather easy set up, I assure you. The trick is getting the file path right, and I’ve practically done that for you! :) (Hint: Practically means you need to put your animations in the folder we define as #filepath. And the names of the CAF files should sync up.)
Try to ignore the header and footers, the meat of a ChrParams file is it’s AnimationList. (If you don’t believe me, check out basicPlayer.XML) Anyway, we define a filepath, tell CryEngine where to save our database, and declare which animations we’re using. Simple stuff. As long as you remember to put the animations into the folder you just defined.
Oh, one other thing about the chrParam file. The filename should be exactly the same as the *.chr file. This is for automatic loading of the script. (Otherwise you’ll have to set this up every single time. Me, I like saving time.)
The other script is a little more involved. It takes the assets we’ve created, and tells them how to behave as a weapon. Fortunately, if you have followed my tutorial up to this point – the chances are very good I’ve practically done the work for you. (As I’ll be providing the xml script used in this tutorial as reference. It’s a basic example, but it definitely works.)
It’s basically divided into sections, we’ll cover them one at a time.
First up are the params, these define settings. The important one is pose, the rest are just generally left as-is. Pose tells CryEngine what to derive from, “nw” is the default animation set provided by CryTek.
Geometry tells the Game where to look for the weapon models. These are just filepaths. As long as your geometry is located where you say it is here, things will work.
Each action can be defined, given a custom animation, and sound effects. In fact you can give them multiple animations, and it’ll randomly pick from them. Worth noting though, that target=owner is the third person rig associated with the character (usually his visible shadow.) The other, target=firstperson should be obvious, it calls the arms to action.
Firemodes are just that, types of attacks. We have one, a melee swing. All the parameters are fairly important, and hopefully obvious. Helper is the HelperNode (or joint) we created to tell CryEngine where the action is. Damage is well, how bad it stings. Impulse is the amount of force behind the blow. (0 for testing purposes, you’ll probably want a value of some kind here.) Delay is the amount of time (after the click) before the impact. And duration is the play speed (It’s a scalar.)
You’ll want to make sure these script files get to the right folders. For the chrParam, put it in the same folder as the *.chr file (for automatic loading.) The other xml file should be placed inside the CryEngine folder at Game/Scripts/Entities/Items/XML/Weapons. (You may have to create one or more of these directories.)