Documentation/Tutorials/Main Character Replacement

From NeoAxis Engine Wiki

Jump to: navigation, search
Go to higher level

Contents

Introduction

In this tutorial, we will learn how to replace the main character (rabbit) with any other character.

The first part of the tutorial shows you how to replace the rabbit model, without creating a new entity by simply replacing the model of the rabbit. In the second part, we will create a new character from scratch.

Model Replacement

We will replace the rabbit model with another model in the Resource Editor. The details of the rabbit game object, is located in the Rabbit.type file in the Data\Types\Units\Rabbit directory. You can learn more about the game objects here.

Change person1.jpg

Double click the Rabbit.type on the left side of resource editor to enter editing mode.

To change the model associated with the type, we must change the mesh associated with the Rabbit.type file. Click on the rabbit in the preview window, to select the rabbit mesh.

Change person10.jpg

This will make the attached object editable. We now need to change the value of the property MeshName. To do this, click on the "..." in the MeshName field.

Change person11.jpg

A new window will pop up that allows us to select our new model mesh. Here you can select the mesh of your choice. In our example, we will choose the mesh of a zombie.

Change person6.jpg

For the chosen mesh, it is necessary to specify the position, rotation and scaling. This is necessary to ensure that the model is grounded on our landscape, is at the same level as the camera and also fits in our map. You must play with these settings as they are specific to each model.

Change person12.jpg

Once this is done, we need to return to edit the animation settings that are available as part of the type specification. Select the Rabbit box in the Objects window.

Change person14.jpg

Now you can configure the animation of the attached model. This must be done in order to play the specific animation during a particular state of the model in your game. We must change the animation state of rest and walking by changing the parameters IdleAnimationName and WalkAnimationName respectively.

Change person8.jpg
The list of all animations can be viewed in the Resource Editor, open the file with a mesh and expand to show the list of Animations.

For the changes to take effect, you must save the file by clicking on the Save buttong (button with the floppy).

Change person13.jpg

Once the above steps are carreid out, you can see the new model by running the Game.exe file in the NeoAxis\NeoAxis Engine Non-Commercial SDK 0.91\Game\Bin folder.

Change person9.jpg
To see your character in the game, you must select the third person camera by pressing F7.


Character Creation

In this section, we shall learn how to create a new character type. It is assumed that you have understood the previous technique that we used to replace an existing model.

Creating a new game type

Create a new directory in the folder Data\Types\Units. You can do this in the Resource Editor and navigate to the folder. Right-click on the folder Units and from the context menu choose New Directory. Enter a name for the new directory (in our example, we call it NewCharacter) and press Enter.

Change person15.jpg

Now right-click on the created folder and click New Resource.

Change person16.jpg

A new window will pop up that lets you choose the type of the new resource. Select Entity Type and click Continue.

Change person17.jpg

The New Entity Type Wizard window will appear. In the window, you must specify the name of a new type and its class. Class, in our case, will be the PlayerCharacter class. After you specify the name and class, you must click Next.

Change person18.jpg

A new entity type is created with the name that we specified. In our case it is NewCharacter.type. This entity type does not have parameters configured and you will need to customize these for the type. To do this, you should double-click the file which takes you to edit mode.

Change person19.jpg

Our first step will be to attach a model to the entity type. Right-click on the type in the Objects window, and then click Attach Object. In the menu that appears, click Mesh.

Change person21.jpg

In the Choose Resource window, select a file with the model and click OK. In our case, we choose the Zombie mesh.

Change person22.jpg

Modify the settings of the Position, Rotation and Scale parameters, if needed to ensure that the model fits well into your game. You can view the effect of the settings in the Preview window.

Change person23.jpg

We now return to editing the type. Select the character in the Objects window.

Change person24.jpg

We add the names of animations for the idle state (IdleAnimationName) and walking (WalkAnimationName), just as we did this in the previous lesson.

Change person25.jpg

The entity has a few more parameters that you can set. FlyControlForce - the force with which the character moves in flight FlyControlMaxVelocity - the maximum speed of movement in flight WalkForce - the force with which the character moves while walking WalkMaxVelocity - the maximum speed of walking

Change person29.jpg

This completes the creation of a new entity type in the Resource Editor. Do not forget to save your changes through the menu File -> Save, using an icon with a floppy disk or by simply pressing Ctrl + S.

Change person20.jpg

Modifying the Source

After editing the type is complete, you must change the source code to use our newly created entity type as the default character for the player.

Open the solution (file with the projects) in Visual Studio "NeoAxis\NeoAxis Engine Non-Commercial 0.91 SDK\Game\Src\NonCommercialLicense.sln". In the project GameEntities open the file GameWorld.cs. Find the function ServerOrSingle_CreatePlayerUnit. In the code

string unitTypeName;
if( !player.Bot )
	unitTypeName = "Rabbit";
else
	unitTypeName = player.Name;

Replace the line unitTypeName = "Rabbit"; with unitTypeName = "NewCharacter";, where NewCharacter is the name of the entity type that we created.

Next build the project by clicking Build -> Build Solution.

Attention! Before building the solution, ensure that the Resource Editor is closed, so that NeoAxis Engine libraries can be recompiled.
Change person27.jpg

Start Game.exe from the folder NeoAxis\NeoAxis Engine Non-Commercial 0.91 SDK\Game\Bin, to look at your character in the game. You may also choose to Run the solution from within your Visual Studio.

Change person28.jpg