In this tutorial, we explain how to make a third-person character, like the ones found in several RPGs. The player controls the character by clicking on the ground from a third-person perspective.
Contents |
We developed this tutorial inside an arena named Creating3rdPersonCharacter in the project Free4All. You may clone the arena and see this tutorial in action. Even better, you could create a new arena inside that project and follow this tutorial to create a new character from scratch.
Character Object
Firstly, create an object called Character in the arena, using the default object template.
- Right-click on the arena object in the tree >> new >> object, like so:
- Name the object Character and select the object template default:
If you want to make a multiplayer game, you should consider creating the models, interactions, etc. inside a presence template, because, well, that's what they are made for: to create objects that represent players in the game environment. More about making a multiplayer game here.
Character Model
The first thing you need is a model for your character. Right-click on the object Character >> new >> model. This will open the Model Editor to create a 3d model. Name the model my_character_model, pick a mesh and press "Save". We used a mesh called aztec_warrior_blue, which is part of the Media Library Aztec. This Media Library is free, you just have to subscribe it in order to use the model.
The physics engine inside ludiloom has several features to manage character control: physics, movement, interpolation, etc.. We will show how to use these features in this tutorial. More about this interface here. After pressing "Save" in the Model Editor, open the Physics Editor. Choose "Character" in the physics type box.
Configuring the physics is mostly a task of tweaking, so you are more likely spend more time in the physics interface after the character is 'working' than at this point. You can find a more detailed explanation about this interface here, but here are some things you have to do:
- Set the Mass to 100, so your character behaves properly to gravity and other physical forces.
- Set synchronization to global only if the game is multi-player.
- Enable collision and gravity.
- Set the offset, scale and rotation of the capsule. If you look at the 3d model in the game scene while this editor is open, you'll see a green capsule around the model. This capsule is what really matters to the physics engine. Sometimes we have to adjust the capsule to the model. In our warrior model, we adjusted the vertical offset and the height of the capsule.
- Set the speed of the model. We set it to 50.
- Configure the walking sound.
Movement
To create the interaction to make the character move, right-click on the object Character >> new >> interaction. Each interaction contains a Lua script. Find out more about scripting in ludiloom here. Name the interaction as goTo.
Add a parameter named position with the type Array of Numbers to the interaction, as shown in the picture above.
Write the script in the interaction to make the character walk to the position defined in the number array position:
local m = this:getModel("my_character_model"); m:goTo(position[1],position[2],position[3]); m:playAnimation("walk",4,true);
The line 1 binds the model of the character to the variable m. The variable this is the object that contains the interaction (Character), and my_character_model is the name of the character model previously created. Line 2 tells the character model to go to the position passed to the interaction. Finally, line 3 starts playing the animation walk in the model with speed 1 and in loop.
You find a complete description of the Lua API here. In this script, we used the functions getModel, goTo and playAnimation.
Animations come within the mesh. You can see the list of animations a mesh has in the Model Editor. Learn more about exporting models to ludiloom here.
We want this interaction to execute when the player clicks on the terrain. To link the mouse-click event to the interaction goTo, create a listener in the arena. Right-click on the arena object in the tree >> new >> listener.
You will see the Listener Editor window, like this:
Then configure the listener:
- Set the listener type to Mouse.
- Set the action to Mouse Left pressed.
- Press the button more. It will open that Interaction Select window, where you can browse the Tree and pick the interaction. Find the object Character and select the interaction goTo.
- Click on the parameter position and press the button set. We do this tell the listener what to send to the parameter position. Set the where field to listener and listener to Absolute Position.
- Press new.
You have to create another interacton to stop the animation when the model reaches its destination. To create this interaction, right-click on the object Character >> new >> interaction and name it stop. This is the code that should be in the interaction:
local m = this:getModel("my_character_model"); m:stopAnimation("walk");
Now you need a listener to execute this interaction when the character stops. Right-click on the model my_character_model >> new >> listener. Set the listener type to Physics, action to movement stop and interaction to stop. Press new.
In the end, you should have something like this:
By now, your character should be fully operational. Change to play mode (alt+1) and give it a "test-drive"!
Configuring the camera
Finally, you have to create a camera to follow the character around. To create a camera, right-click on the arena object in the tree >> new >> camera like this:
In the Camera Editor, write cam in the name field and activate the Use Mouse Wheel to Zoom check-box.
Press new to finish creating the camera. Now that the camera is in the game environment (you should be seeing it in the position (0,0,0), you have to rotate it so that it points to the camera base. Click on the camera, open the Scene Editor and activate the rotation gizmo to rotate the camera. To change the rotation axis, press tab. Rotate the camera until you have something like this:
Then, click on the base of the camera (the arrow thing) and rotate it 180ยบ horizontally:
Finally, we have to attach the base of the camera to the model. Right-click on the model >> attach >> camera >> cam:
Open the console (F11) and write the following code to activate the Camera:
Arena:setActiveCamera("cam");
And that's it! Switch to play mode (alt+1) and test your character:

















