Documentation/Tutorials/Main Character Replacement
From NeoAxis 3D Engine Wiki
|Language:||English • Russian||Status:||Not Approved|
In this tutorial, we will learn how to create character. At the moment, it's possible to create two kinds of characters - an AI controlled character and a player character.
In the first part of the tutorial, we will learn to create a character from scratch. In the second part, we will create a new character by copying and modifying an existing one. In the last part, we will see how to use the previously created type in a map.
Creating the Object Type
To start with, we will create a player character. In addition, instructions for creating an AI controlled character will be given in footnotes. First of all prepare resources required for the character. There are:
- 3D-model (.mesh),
- skeleton (.skeleton),
- material (.highMaterial),
- animation tree (.animationTree),
- textures (.dds),
- sounds (.ogg),
- additional content, weapon (.type).
Run the Resource Editor.
Firt of all, create the folder for our new type. Simply right click on the Data\Types\Units folder and select New -> Folder in the context menu.
Name the folder: MyCharacter. We will now put our resources into the new folder. For this example, we will use pre existing resources that comes with the Neoaxis SDK. From the Data\Types\Units\Zombie directory, copy the following files:
Select the files, right click and select Copy in the context menu. To copy them in the MyCharacter folder, just right click on it and select Paste.
Now let's edit our resouces. First of all, rename them to MyCharacter. Right click on an asset and select Rename in the context menu.
To edit the MyCharacter.highMaterial material, select it in the folder and click the Edit button in the main tolbar. You can also just double click on the asset in the tree view to enter edit mode.
In the Properties window, select the Diffuse1Map property and press the "..." button in front of it. In the popup window, select the MyCharacter.dds texture from the Data\Types\Units\MyCharacter folder and click OK.
To save the changes, press the Save button in the main toolbar.
Now open MyCharacter.mesh to edit. In the property's window press the button "..." in front of computer field SkeletonName. In the appeared window select a file MyCharacter.skeleton from the folder Data\Types\Units\MyCharacter and click the button OK. After that click the button "..." in the property MaterialName of the submesh 0. In the appeared window select the file MyCharacter.highMaterial from our folder and click the button OK.
Save changes by clicking the button Save in the main toollbar.
We can now start to create a character type (.type file).
Right click on the MyCharacter folder and select New -> Entity Type in the context menu.
In the popup window, name the type — MyCharacter, class — PlayerCharacter and click the Next button. To create an AI character, you would need to choose the GameCharacter class.
The type file is a resources container. You will now need to add resources to the type.
Enter edit mode for our newly created type file, select it and click Edit button in the main toolbar.
Start by attaching the character 3D-model. In the Objects window, right click on the root object and select Attach Object -> 3D Model.
In the popup window, select the MyCharacter.mesh file from out folder and press the OK button.
You can now see the character model in the type file.
Now we will move the character a bit, so the physical model will match the character mesh dimensions. By default, a capsule is used as physical model. This physical model is used to handle the collisions of the character with the environment. To see the character's physical model, check the Show Physics property in the property window. Align the character model and the capsule. To do this, select the attached 3D model in the object window and type the following values in the Position field "0 0 -1.15". You can also move the mesh using the move tool located in the top toolbar.
You now need to take care of the animation of the character. Neoaxis uses a .animationTree file as a description of the available animations. Add the animations tree file to the new type. To do this, click on the "..." button next to the AnimationTree field.
In the popup window, choose the MyCharacter.animationTree file and click on OK.
We will now change a few parameters of our character. For this, select the MyCharacter type (root object) in the object window.
In the Character section, we will setup the properties that affects the character's movement:
- FlyControlForce = 49000 (power of the force used for flight control)
- FlyControlMaxSpeed = 3 (maximum speed in flight)
- WalkForce = 280000 (force applied when walking)
- WalkForwardMaxSpeed = 2 (maximum speed when walking)
In the Dynamic group, specify the following parameters:
- HealthMax = 40 (maximum health points)
- Substance = Flesh substance - flesh)
- TargetPriority = 1 (priority target for the enemy)
In the Entity group:
- CreatableInMapEditor = True Allows the creation in the map editor)
- NetworkType = Synchronized (network type - synchronized)
In the group GameCharacter:
- OptimalAttackDistanceRange = 0 1 (optimal distance range for attack)
Now, in the Unit group, click on the "..." button next to the InitialAI field (artificial intelligence, defining behaviors), select DefaultGameCharacterAI (artificial intelligence character default) and click OK.
In the same group, Unit, enter the following values:
- FPSCameraOffset = 0.3 0 0.7 (shift the camera in first person view)
- ViewRadius = 40 (sight range)
Finally, save the file. To do this, press the button with the floppy disk icon in the main panel.
The configuration of the character is complete and we can use it on one of the maps.
Create a New Object Type by Copying
Due to the fact that different characters types often have many common properties, creating a new character based on an existing one is the fastest way to proceed.
To copy a character type, copy in a new folder the "'.type"' you want to copy as well as all the necessary resources.
After that, rename the type file, and open it for editing. You can also edit the files manually in a text editor.
Now, the configuration of your character will be done the same way as described in the previous section. We have to delete the unecessary meshe(s), then add or replace the ressources with the ones we want to use ( mesh, animations tree, AI etc.) You also need to configure the various properties of the character.
It is important to remember that the class of a type cannot be changed. Therefore, the types of the player controlled character must be created using the "'PlayerCharacter"' class whereas AI controller characters need to use the "'GameCharacter"' class.
Replacing the Player Character on a Map
In order to test our newly created character, run the Map Editor and open any map. For Example, VillageDemo.
In the Objects window, select the root object (Map).
In the Properties window, select the PlayerUnitType property and press the "..." button.
In the popup window, select the MyCharacter.type we have created. It's located in the Data\Types\Units\MyCharacter folder.
Press the button with the floppy disk icon to save the map. Then run the simulation by clicking on the Run button in the main toolbar.
You can now control your new character! To ensure that the character has really changed, change the camera view to 3rd person (key F7).