Published on the 30th November 2009 at 11:59am
In this tutorial for the Unity game engine we will be learning how to create a 3rd person character controller. For new Unity developers, the question of how to create a working 3rd person controller is possibly one of the most asked questions out there.
While there are a number of guides out there many new developers feel that they are difficult to understand, difficult to follow and awkward to use in practice, this is because they are either tied into a full game case study and therefore contain a lot of game specific code, are over complicated and aren't designed to be taken as a controller framework.
So we've attempted to fill that void by creating this 3rd person controller tutorial which will take you through the steps required to implement a functional 3rd person controller which is complete enough to be useful but simple enough to be easy to follow and extended to meet your games requirements.
The bottom line is, 3rd person controllers are actually very simple to implement but are made difficult due to the lack of documentation with a reasonable point of entry.

Before we begin this tutorial you will need a character with at least three animation cycles, don't worry if you don't have one as we've supplied one below. If you want to use your own then you'll need three animation cycles:
1. An idle cycle (so standing still)
2. A walk cycle
3. A run cycle
If you have a character and want to use it then make sure you have at least those three animations. Also if your using a Biped Rig created in 3D Studio Max then make sure the Pelvis is named "rootJoint" as Unity looks for that joint as the root. If your lost already, check our character setup tutorial.
If you don't have a character then you can download a 3d studio max test character here which includes the three animations we will need in this tutorial.
Once you have a character, either our test character or your own, then we're ready to go. Naturally before we run off and create a controllable character we'll need to setup some kind of a game level for the character to walk around. So follow these steps:
1. Create a new project by going to "File -> New Project". You don't need any of the asset packages for this tutorial but we're including the standard asset package anyway so we can grab the sky box and some terrain textures.
2. When the blank project is loaded up we will want to create our scene which will contain a textured terrain, a sky box and a directional light, so:
- First create a terrain by going to "Terrain -> Create Terrain".
- Second create a directional light by going to "GameObject -> Create Other -> Directional Light", then move it upwards and rotate it down so its shining down onto the terrain.
- Now select the Terrain in the Hierarchy then select Paint Terrain Texture button in the Inspector and add a default texture
- Finally go to "Edit -> Render Settings", then in the Inspector set the Skybox Material to one of the sky boxes (i.e. blue sky or sunset)
You should then have a very basic level like the one pictured below.

Now we need to import our character into the project, so in the Project Panel, right click and select "Import New Asset". When the dialogue appears, find your character and import it.
Depending on the character it may take a short while to import, but when its in you should see the characters prefab in the Project panel.
If you are using your own character which has textures then you will want to import the textures and assign them to the model as well. Details on how to do this are contained in the Character Setup tutorial linked in the introduction above.
So lets continue, in part 2 we will setup the animation cycles and input settings.
| Latest Comments |
| dracula |
|
The tutorial looks great but I have only read through it so far.
I did download character.max but it wouldn't open (file error message) I'm using 3ds max 2009 Thanks |
| dracula |
|
Great stuff, even better would be an fbx file. I use an older Max 8 (c2005) at work
|
| FizixRichard |
|
I've uploaded a new version of the zip file which contains the MAX 2010 version of the character and an FBX version of the character.
I've tested the FBX in MAX and in Unity and it loads fine. If there are any problems with that version do let me know. One last thing, if you notice the rig has a few artifacts I'm aware of that (the character was rigged up soley for this tutorial so its limited in its production values). |
| dracula |
|
I tried the model (character.fbx) in Unity and it went through its animation cycle okay. I havn't added the script yet
Thanks very much, it's appreciated |
| TheClaus |
|
Great tutorial. I was able to get everything working as I followed the tutorial. I notice though that it doesn't matter where I place the camera rotation wise once I add the smoothfollow it doesn't care anymore about the placement. I play with the Distance and Height but can't get it to look like other 3rd person cameras(WoW, EQ2, etc...) It is almost like it is pointing down towards the player a bit too much.
Any ideas? |
| FizixRichard |
|
Hi TheClaus,
Glad the tutorial worked for you. The problem with the smooth follow camera is that it uses a fixed vertical axis which means it doesn't quite work all the time. If you to into Standard Assets and find the smooth follow script you can edit the script itself from there in order to adjust how it works. If you want a WoW/EQ style camera controller then thats quite a bit more work than using a standard script (which is what we did in this tutorial). You need to script the camera position, rotation (vertical and horizontal), vertical limits, collisions (so it doesn't go through objects) and zooming. We're looking at doing a tutorial on a camera controller which works as follows: 1. Can switch between 1st and 3rd person 2. Can rotate around the camera 3. Can rotate up and down (above the character) with a top and bottom limiter 4. Can zoom in and out of the character (with limits) 5. Can collide with terrain and objects to prevent going through objects 6. Follows the character smoothly when moving This is a bit of work to do well (many commercial games have bad camera controls), if we do that tutorial we will be doing a sterling job on it rather than a "that'll do job". I think it would be nice to evolve this and the collision tutorials first with 2nd parts to each and then do the camera one. |
| FizixRichard |
|
I started a tutorial on 3rd person cameras:
[url]http://www.unitylabs.net/tutorials/gameplay-mechanics/third-person-camera-controller/1[/url] It all works except for collisions and switching between 1st and 3rd person mode. It smoothly follows, rotates with limiters, has a zoom feature and rotates smoothly back behind the player as you move :) |
| TheClaus |
|
Hi FizixRichard. I was playing with your new tutorial for third person and found some errors. Was going to post under that thread but it looks like it doesn't exist. Let me know if you want them here or in a new thread.
Great tutorial btw I was able to move the camera around the player and it was very smooth when turning. I have some questions about running an things but will wait to hear from you. Thanks again for the hard work. It is paying off as I am learning more and more about Unity from them. |
| FizixRichard |
|
The 3rd person camera tutorial isn't finished so might have a couple of bugs in it or errors; so PM them to me and I'll take a look at them.
I'll be adding a discussion thread for it when the tut is finished. |
| maggot |
|
Hi, I just completed this tutorial with one of my own characters and it works fine. Thanks for supplying the tutorial!
|
| FizixRichard |
|
Glad you found it useful!
|
| gav318 |
|
Awesome tutorial!!!
I was really struggling with the Lerps platformer documentation on the official Unity site and this was so simple to implement and easy to follow I actually feel as though I learnt something. I find the official tutorials very difficult to get my head around, way to much information at once. Keep up the good work and Im really looking forward to seeing what you come up with next! |
| Lord Marcus |
|
Hello, I'm new. Sorry for poor english: I'm italian.
I found your tutorials very interesting for beginners. I hope I can improve in using Unity... I have one question. I have all my animations for my character stored in different files. I made them for another game editor. Anyway, I imported them as "model@animation", as the rerference manual said. They separatly work correctly. And the manual says they'll be referenced by the "model". The manual let me understand there will be no problem. I'm following this tutorial to let my character walk, but when I play, it display a NullReferenceException at the line where there's the "walk" animation in the script... It looks like it can't read the "model@animation" I imported. Should I put all animations in one file? |
| Lord Marcus |
|
Ok, I did it. I found the solution on this same forum. I read for importing character it's a conventions to name the root as "rootJoint". I applied it to my character and now it works fine :)
|
| fdslk |
|
Amazing tut! This really help me out, but I only have one question... Is there a way to make it without the euler rotation system? I've tried almost everything to make the model just to move towards it's rotation.
I mean, I want to make the traditional: press left and move straight foward left, press right and move straight foward right, press up and so on... and then press up+left and rotate+move diagonal up-left. |
| tyree |
|
Im having no success with the third person controller tutorial. I'll be trying it again later. but why didnt unity just include a general purpose move model script with keyboard control for a 3rd person character
can you do a tutorial showing how to assign keyboard control just keyboard control to a model |
| Zynt453 |
|
I followed the tutorial, but my character just walks on the spot and doesn't actually move anywhere, I can turn him and he animates when I'm pressing the keys to walk, but he doesn't actually move, any ideas why?
|
| pixelist |
|
Hello Unity folks
I'd like to use my own character to follow your third person tutorial, but when I click on the link for "check our character setup tutorial" I am returned to "third person character controller tutorial page. Am I missing something? Please help thanks |
| wakkamis |
|
[QUOTE=pixelist;252]Hello Unity folks
I'd like to use my own character to follow your third person tutorial, but when I click on the link for "check our character setup tutorial" I am returned to "third person character controller tutorial page. Am I missing something? Please help thanks[/QUOTE] Same here. Would be awesome to see that as well. Thanks for the helpful tutorial! |
| Corrupted Heart |
|
I am trying to convert the code to c# because I prefer coding in that.
However I run into an error with: [CODE] if(Input.GetAxis("Horizontal") && !Input.GetAxis("Vertical")) { animation.CrossFade("walk"); } [/CODE] The error is: "Cannot implicitly convert type `float' to `bool'" and: "The `!' operator cannot be applied to operand of type `float'" How do I convert this into C#? |
| orifrish |
|
why no one answers on my question about the flight tutorial problem? there are missing pages!
|
| Bryan A |
|
Thanks for the nice tutorial. I've tried it with my own character and it work fine. Can I request a jumping movement included in the script. I would like to know how that can be implemented. I'm not a programmer by the way. Just and artist.:)
|
| samuel |
|
everytime i put in the script i get the same error. i dont know why. i try running the game and i can only move left or right i cant move forward or back. can someone help me here is the report.
!IsNormalized (normal) UnityEditor.Handles:Internal_DrawCamera(Camera, Int32) UnityEditor.Handles:Internal_DrawCamera(Camera, Int32) UnityEditor.Handles:drawCamera(Rect, Camera, Int32) UnityEditor.SceneView:OnGUI() System.Reflection.MonoMethod:InternalInvoke(Object, Object[]) System.Reflection.MonoMethod:InternalInvoke(Object, Object[]) System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo) System.Reflection.MethodBase:Invoke(Object, Object[]) UnityEditor.HostView:Invoke(String) UnityEditor.DockArea:OnGUI() [c:\builds\checkouts\branches\unity-2.6.x\runtime\geometry\Plane.h line 72] |
| PaulX1 |
|
I've followed your tutorial, and I have hit a snag. I've followed the scripting tutorial on page 4, but I can't get my character to move at all. He will rotate and animate, but he won't actually go anywhere.
I added a Debug.Log (moveDirection) to the script to see what was happening, and I found that the only number being updated was the middle one (0.0, -8.4, 0.0). I'm assuming that's the Y axis. I've played around with the Character Controller, but it doesn't seem to make a difference. Is there anything I might be forgetting? |
| PaulX1 |
|
The answer is that the axis of the character is different than that of the sphere, which is aligned to Unity's default axis settings. By default, X is sideways, Y is up, and Z is forwards, while the default settings for Biped in 3D Studio MAX 7 is X is sideways, Y is forwards and Z is up, meaning that this code is attempting to make the character move upwards instead of forward. So, instead of this
moveDirection = Vector3(0,0, Input.GetAxis("Vertical")); It's instead this moveDirection = Vector3(0,-Input.GetAxis("Vertical"),0); The next question I have is, is there a way to change the axis of the character in Unity? I tried to change it in MAX and the whole character moved. |
| Napalman |
|
Hi everyone!
Please, forgive me if I'm not really in topic but I have a question very close to the Third person controller tutorial (amazing!) written down by FizixRichard. So, My question is about the line "if isgrounded = true": I need to make a simple platform that goes up and down and lift up my character, if the character goes on the platform. I'm afraid that this code line keep the character on the ground and avoid to let it goes up with the platform. Please, can you suggest me an integration or a trick for my code (I repeat, the code is the one written by FizixRichard in his amazing third person controller tutorial). And, please, note that I'm a real novice, so be patient :) Thank you in advance! Nap |
| Adam We |
|
Hey I'm having some problems, I followed the tutorial exactly and the character(the default one provided) won't move forward, he'll move backwards and turn, but he wont move forward, I've checked the input and the code was the paste from the tutorial, what do I do?
|
| Nubux |
|
hi, thank you for this great tutorial !!
sorry for my poor english, i'm french.... Even if i'm a total beginer in scripting (more a 3d/2d artist) i have follow your tutorial and learned a lot. But i wonder if it's possible to make the character jump...I tried for hours but did'nt find a clean solution. i add this code but it doesn't work (its one exemple of my research) : [QUOTE]if(Input.GetButtonDown("Jump")) { robotnik.animation["saut"].speed=1.5; robotnik.animation.CrossFade("saut"); moveDirection=transform.InverseTransformDirection(0,jumpSpeed,jumpSpeed); }[/QUOTE] He jumps in Y axe but in Z it follows the world space instead of local one... Its a bad code of course but i want him to jump forward... other question: do you plan to make more of these tutorials? |
| View All Comments And Create Comment |