Robot Series – Part 01 – Movement

In this Unity tutorial series, we’ll be covering many different aspects of the program to create all of the elements needed for a third person action/ platformer game.

In this first part of the robot series we’ll be covering how to ad a Character Controller and movement scripts to the character, using both the standard default scripts, as well as writing a custom one.


Leave Comment


85 Responses to “Robot Series – Part 01 – Movement”
    • Posts: 109

      Yes, it is. However, you should be able to use any character you want, provided you have the animations. =)

    • Posts: 1
      Eric Miller says:

      my model is in fbx. my model has walk and idle on the same key frame. i have it imported in unity. but as i click on my model there is no wrap mode or loop option? i did set up my walk and idle in unity. but where is the other options?

  1. Posts: 10
    Daniel Wentzell Jr. says:


    Thank You. Will wait for an hour or so before downloading.


    • Posts: 46

      You can go ahead and download it, the source files have the original HD video; we’re still looking into why the Vimeo version isn’t available as HD.


      • Posts: 10
        Daniel Wentzell Jr. says:

        Thanks. Downloading now.


  2. Posts: 1
    ZoyncTV says:

    is there an advantage to this compared to blender? for instance is this easier or able to do better things? (i haven’t seen it before I’m here because you posted the link to the website on blender cookie… which is awesome)

    • Posts: 109

      Hi ZoyncTV!

      I find Unity to definitely be a better choice for making games than the BGE. In short, the reason being that Unity offers more and is more flexible. Unity is a dedicated game engine that has heaps of functionality and little things (as well as big ones!) that makes your life as a game designer a whole lot easier. A few examples are ‘standard’ functions that are meant to be overridden (i.e.: Start(), Update(), FixedUpdate()), little built-in methods and properties (i.e.: Vector3.Distance(), characterController.isGrounded or Time.deltaTime), a component-based workflow, better support for building (to PC, Mac, Web, iOS, consoles), NVidia PhysX physics engine and probably some stuff I’m forgetting right now.

      Don’t get me wrong, I still love Blender! But the BGE will never be able to compete with engines like this or UDK for instance (and they shouldn’t want/ need to!). Blender is a great all-round software package which happens to also provide a game engine built in. And for some games that’s sufficient.

      I could keep talking about this, but it’s probably best to just get your feet wet and find what works for you yourself. =)

      Hope this answered your question!

  3. Posts: 1
    Dial3ct says:

    Hey, tutorial is great. Just have a question however. When I export my blender objects as fbx, if I have textures added to the materials in blender it doesn’t let me reassign the textures to the materials in unity. Any ideas why?
    Thanks, dial3ct

    • Posts: 109

      Hey Dial3ct,

      How is it not letting you assign them in Unity? If you’re missing the slots you need to set the material’s shader to a different type that supports all your texture maps.


  4. Posts: 7
    Michael says:

    Hmm, the video freezes at one frame, and stays there for the rest of the video.

  5. Posts: 3

    um, i got a problem

    i used the 3rd person controller script, and i inserted my own animations (which i did in blender) in each slots, but when i try to walk, run, idle or jump the animations wont work :/

    • Posts: 109

      Hmm, ok, debugging time! If you set the default animation to ‘walk’ for instance, and check ‘play automatically’, does it work?

      (PS: I would like to strongly urge you to go with the custom script option!)

      • Posts: 3

        yup i did, but still the same result :/

        i tried the custom one, and it worked 😀
        thanks for tut btw!

  6. Posts: 1

    omg when you coughed u scared the sh@*# out of me… but still a pretty awesome tutorial! thank you!

    • Posts: 109

      Oh, I’m so sorry; I thought I got those all out! Do you remember around where in the video it is?

      • Posts: 33
        Gary Parkin says:

        I heard it too. It was somewhere in the beginning. I almost jumped out of my chair. it’s because your voice comes over low.
        You look much younger then your voice. :)

        Thanks bunches for these tutorials. And I enjoy your ramblings. Make it feel more real then just a video.
        I’d also like to see a more optimized script. Or when I learn I can.
        I’m a software developer by trade so the scripting makes me feel at home.
        If I wanted to create a control panel for the buttons, is it possible? Almost like Flight Simulator has a cockpit. I have another use for this engine.

      • Posts: 109

        Hey Gary,

        With Unity you could definitely make a set of 2D/ 3D buttons that players can press, turn, etc. Is this what you had in mind?
        And thanks for the positive words! I’ll definitely do a tutorial on optimization sometime; just not sure when yet. =)


      • Posts: 33
        Gary Parkin says:

        Hi Patrick
        I found it! 7.56 is the cough. I was re-watching the tutorial and following along.

  7. Posts: 1
    Bart says:

    Great tutorial but any info on the HD version?

  8. Posts: 1
    Ryan G says:

    i heard udk is better than unity…. is that true

    • Posts: 109

      Is Maya better than Max? Is Flash better than Illustrator? I’ve never liked calling one program better than the other, it’s how you use that’s important. =) In some cases UDK does have some advantages over Unity (i.e.: Realistic/ next-gen graphics, particles), but it is more limited in licensing and you’ll have to pay royalties over your product if it’s a commercial one. It really boils down to what kind of product(s) you want to create and which workflow you prefer that would determine which engine’s best for you.

      Hope that helped!

      • Posts: 33
        Gary Parkin says:

        I had to look up UDK. And I’m a gamer too. 😐
        It looks interesting to say the least. I’ve built some levels for Unreal, using the old editor but I haven’t played in their full game builders environment yet.
        I do like Unity though. The terrain editor in Unreal looks easier then Unity’s. I started taking a free course in Unity over at 3dbuzz a year or so ago. That’s where I learned most of what I know about 3ds Max.
        I’m looking forward to seeing what you guys at cgcookie do with Unity. If the tutorials are half as good as your Blender ones, I’ll be up and running in no time.
        Thank you for all your hard work.

  9. Posts: 8

    Unfortunately I can’t play the video at all (under OS X Lion) – codec not available, and it fails even trying to find it when it offers to look online :-(

    I have never had any problem viewing videos from cgcookie before. Any chance you can provide the video in your more usual format please?

    • Posts: 109

      I’m pretty sure I exported the video as we usually do, but I’ll take a look at it. We’ll get back to you on this ASAP; sorry for the inconvenience!

      (PS: Perhaps as a workaround you could try playing it in VLC?)

    • Posts: 62
      Wes Burke says:

      Definitely give it a go in VLC Video player, but I think we are going to work to break this video up into two parts as well and repost them both here. The length we believe is mucking up a few things. :)

      • Posts: 8

        no worries – thanks for taking a look. For now, i’m just watching via the web-page, but it’d sure be nice to have this resolved.

        ps I’ve got through about half of the tutorial so far – it’s very useful. Thank you Patrick! I’m still feeling very newb with Unity. It all helps!

  10. Posts: 8

    NB Regarding my previous comment: I am referring to the downloaded version. The video seems to play ok streamed from the web-page itself.

  11. Posts: 2
    Carl Birch says:

    Hi was following along, but I’ve hit a snag, I’m getting a nullreference exception “UnityEngine.CharacterController.Move(Vector3 motion), any ideas on how to solve this?

    Here’s The Code So Far:


    var speed:float;

    private var charController:CharacterController;

    function start() {
    CharController = GetComponent(CharacterController);

    function Update () {

    if(Input.GetAxis(“Vertical”) > 0) {
    charController.Move(transform.forward * speed * Time.deltaTime);



    Everything looks identical to what you have done :(

    P.S Thanks for the great tutorial

    • Posts: 2
      Carl Birch says:

      I now feel stupid :P, capitalisation errors on function s/Start () {} hope this may help someone else :)

  12. Posts: 5

    I did a fps with this code but had some problems with falling in the wrong direction
    I replaced all gravityFall with moveDirection.y and just moveDirection if its between bracelets var should be set up like this:
    private var moveDirection : Vector3 =;

    and you should remove all transform.up as well

  13. Posts: 5
    bk9iq says:

    Thanks for the Tutorial.. very useful especially because you try everything while recording (not pre-set or memorized) … Is there any estimated release date of Part 2??

      • Posts: 5
        bk9iq says:

        Thanks so much … I can’t wait …

  14. Posts: 46

    Just did the tutorial. Really cool but might be a little bit beyond me. I get the jist of how the variables and all are working but get completely lost sometimes. Great tutorial though!


      • Posts: 46


        Looking forward to checking that one out, I’m currently working up the list from bottom to top to catch up! I think you are doing a great job, I’ve just never been much of a programmer. I’ve done HTML and Javascript back in the day but it’s been a long time.

        I understand programming concepts, If then and If else statements, variables, etc. but sometimes a lot of stuff is done and I just don’t get why it’s like that. I’ll be sure to check out that video you suggested and maybe watch this again and it all might make more sense. Practice does make perfect! Thanks and keep up the good work, looking forward to hopefully learning more!


      • Posts: 109

        Ah, I see. If you ever have any feedback whatsoever, please don’t hesitate to say it! If you think I’m going too fast, or maybe not covering enough ground on a specific subject, just let me know. =)

        Best of luck!

      • Posts: 46

        Sounds great! I’ll let you know if there’s anything I think you could elaborate more on. All in all this is more of an intermediate to advanced tutorial and I’m still pre-beginner. haha


  15. Posts: 3
    JON Sloan says:

    First of all, nice intro tutorial to Unity.

    One thing that did bother me from a user perspective was the rotation/turning system for the character. It made it hard or even impossible to keep circling left or right.

    I found that if you replace the following statement at the end of your Update function:

    transform.Rotate(Vector3(0, Input.GetAxis(“Mouse X”) * rotationSpeed * Time.deltaTime, 0));


    if(Input.GetButton(“Fire1″)) {
    transform.Rotate(Vector3(0, Input.GetAxis(“Mouse X”) * rotationSpeed * Time.deltaTime, 0));

    You will then only rotate when holding down the left mouse button (or with Unity’s default setup when you press the Control key and move the mouse). This gives you more control and is still very easy to implement.

    Good stuff though.

  16. Posts: 8
    Ryan M. says:

    Thanks, Patrick, great tutorial.

    I had no idea that Debug.Log() actually wrote a log file. That’s handy!

  17. Posts: 6

    Hey, when I parented the Main Camera to my character, the camera isn’t following the player. The hierarchy panel is all in order, and I can’t find anything wrong. Any insight?

    • Posts: 109

      Hey Therealnoz,

      Is there perhaps a CameraController script or the like attached to the Camera? This may take precedence over the hierarchy.


      • Posts: 6

        Thanks for getting back so soon. I checked over that as well, and that doesn’t seem to be the problem. I tried parenting other objects, and I think it might be my character object that won’t act as a parent.

      • Posts: 6

        Okay, I found that the camera is fully parented to the character, it just won’t move during play.

      • Posts: 6

        Alright, problem solved. I realized that I had applied all of the character properties to the root bone instead of the character himself.

  18. Posts: 8
    Ryan M. says:

    Hey Patrick, great tutorial!

    00:39:58 — “It’s fun though, working on games and watching all the characters come to life. It’s sort of a zen thing.”

    Does CGCookie sell T-Shirts with quotes on them? 😉

  19. Posts: 4
    Edward Casey says:

    Hey Patrick!

    This is probably my favorite tutorial so far! 😀
    I have one question though. I am trying to make a first-person POV camera, but when testing my camera rotation, even with no z-component, doing too much turning will eventually start to make my camera tilt. Right now I am transform.Rotate-ing along each axis in a separate method call. Is there any way I could fix this?

    • Posts: 4
      Edward Casey says:

      Whoops, never mind I figured it out after like 5 minutes of thought. If anybody else has the same problem, the camera should have the up/down rotation separate from the character controller, while the character controller with camera attached gets the left/right rotation. This way you won’t “fly” either.

  20. Posts: 3

    when i look at the API reference some of the stuff you were looking at, e.g transform.forward, didn’t show up for me

  21. Posts: 3

    also it keeps coming up with this compiler error

    Assets/player script.js(13,31): BCE0005: Unknown identifier: ‘Trasform’.

  22. Posts: 2
    wez201102 says:

    I’m trying to write the movement script in c# but i’ve hit a snag. for some reason it worn’t inherit from MonoBehaviour. if i take it out then it doesn’t recognize the Inputs and Debugs.

    • Posts: 109

      Hi Wez,

      How are you trying to make it inherit? The correct C# syntax is:
      class MyClass:MonoBehaviour{}

      You should also make sure to make all the right imports:
      using UnityEngine;
      using System.Collections;
      are the default ones.

      Good luck!

  23. Posts: 1

    Great tutorial :-)

    I have a qustion about the animations made in blender. For example if I want my character to run and on pushing some key make him still running but for example put his hands up – how should I create my animation?
    I mean should I create two different armatures for legs and for torso?
    Or maybe if I create animation for hands up and put it on the layer above run than it will not make legs stop on pushing button?
    I guess I miss some rules of blending animations and have no idea where to look for solution:/

  24. Posts: 2
    wez201102 says:

    ok i’m new to scripting can can’t seem to find it in the Unity API

    what does the “-=” do?

  25. Posts: 1
    James says:

    Great tut 😉
    I was looking for a tutorial on making a custom movement script.
    Although for some reason my idle animation doesn’t play it just stops at the last frame of the walk/run/strafe animation. Any idea why?

    • Posts: 109

      Hi James,

      Are you making sure to call animation.Crossfade(“idle”) continuously in your Update() function?


  26. Posts: 1
    koi says:

    I have really trouble understanding you because you sometimes swallow the endings of words and you have a weird dialect. For non native english speakers like me this is a bit hard to understand sometimes.

    • Posts: 109

      Hi Koi,

      I’m sorry to hear that. I’m not a native speaker myself, so the “weird dialect” you hear is actually a horrendous Dutch accent. 😉
      I always consciously try to articulate as well as possible, though at some point I tend to go to auto-pilot and it may indeed sound a bit less correct.
      I’ll try and keep this in mind though there’s really not a whole lot I can do about it. Any tips on how to make myself more understandable would be much appreciated!

      Thanks for your feedback,

  27. Posts: 12
    CH L says:

    At 41:15, you mentioned that we can overwrite the wrap mode for each animations.

    But I wonder how can we do that? I’m asking because when I import the fbx into unity, all the animations are not modifiable and I cannot set them to use different wrap mode (example: loop for idle animation, once for jump animation etc)

    • Posts: 109

      Hi Chronox,

      To overwrite an animation’s wrapmode in code you can use the following:
      animation[_name_].wrapmode = _wrapmode_
      so for setting, say, the idle animation to loop you could use
      animation[‘idle’].wrapmode = WrapMode.Loop;

      The Unity reference manual has some more information on what’s available here if you’re interested:

      Hope this helped, cheers!

  28. Posts: 2
    Roan says:

    Hey great tutorial. Just a minor problem. After 25 minutes into the video my character falls in the negative Y direction as soon as i press the play button. I have unchecked the player script to see if it was the cause but its still happens. also the problem stops when i unchecked the third person controller script. any suggestions. the character was made in 3ds max so would it have something to do with max and unity orientations?

    • Posts: 2
      Roan says:

      never mind. my characters feet were a little below the plain.

  29. Posts: 1
    masayers says:


    I don’t know if you worked this out by now, but the reason why you didn’t get an error when the variable jumping was not defined is due to the fact javascript uses implicit declaration. It will also exist within the scope it was declared in.

    It means if you address a variable that does not exist it will create one for you. This can be a problem if you make a typo with your code.

    Scope is a programming term used to refer to where a variable is valid and exists. If you declare something in the global scope (i.e. outside all functions), then it can be addressed within any function you have as opposed to declaring it in a specific function.

  30. Posts: 2
    Lia Ark says:

    Hi, I imported the assets by when I putt the robbot on the scene, it has a lot of missing materials and textures and I cant’ see it, it’s the same when I run the provided Scene (MoveTutorial). Any solutions?

  31. Posts: 7
    rahulbha says:


    So, when I use the below code for walking:

    animation[‘robot_rig|walk’].speed = walkAnimSpeed;

    if I press the ‘W’ key down then animation starts and if I then leave the ‘W’ key so even then the animation keeps on looping.

    Any reason why this happens?


  32. Posts: 7
    rahulbha says:

    or do I need to stop the animation when key is up?

Leave a Comment

You must be logged in to post a comment.