Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Controlling animations with scripts: Third-person character controller

From: Game Character Creation in Maya

Video: Controlling animations with scripts: Third-person character controller

So in the last video we covered importing our game character into Unity. So now let's look at some ways so that we can add interaction to our game character, and basically the way we do that in Unity is through scripts. So I am going to go ahead and import some scripts into Unity. These are scripts that come preinstalled with Unity. So this is part of the standard assets package that you should have with your install of Unity. So I am just going to go up to Assets > Import Package and I want to import this Character Controller package. So I just want to leave all these selected.

Controlling animations with scripts: Third-person character controller

So in the last video we covered importing our game character into Unity. So now let's look at some ways so that we can add interaction to our game character, and basically the way we do that in Unity is through scripts. So I am going to go ahead and import some scripts into Unity. These are scripts that come preinstalled with Unity. So this is part of the standard assets package that you should have with your install of Unity. So I am just going to go up to Assets > Import Package and I want to import this Character Controller package. So I just want to leave all these selected.

Just go ahead and click Import. Okay and then when I look in my Project folder, we should see this Standard Assets folder and I can expand that down. And there is a couple prefabricated game characters in here that we can play with too, if you would like. But what I want to look forward down here is this Sources, Scripts folder. This has a couple of pre-made scripts that are going to work to allow us to make our character interactive, so it can move around and respond to user input.

So we'll be going to looking at this ThirdPersonController script in this video. And if I click on that I can get a preview of the actual text. Now there are many ways in Unity to make a script that acts as a Character controller. So you can even write your own, a lot of people do it. Unfortunately, we don't really have the time in this course to go over the fundamentals of scripting and all the things you need to know for scripting Unity. But just be aware that there are a lot of different ways to set up a script that does a similar thing, and if you are interested, I would recommend checking out some of the Unity scripting tutorials.

Okay, so we will just make a couple of adjustments to our character in the hierarchy. The script that we are going to be using is actually expecting a model that scaled much smaller. So I am just going to adjust the Scale in my character's Transform component. And I am going to change it from 1 to 0. 01, so we are just going to temporarily make it a lot smaller and that's going to actually just be easier than adjusting the script itself. So I have got my character highlighted in the hierarchy and let's just go back to the Scene view. I am just going to hit F to automatically zoom-in on that character.

Right now, my character is the only thing in the scene. I actually need to give him sort of a floor to walk on. Otherwise, once we attach a Character Controller script, this character will actually have gravity attached to it, so it will just keep falling into space. So let's go ahead and create a GameObject, and I will just make a Plane. I'll just bring that down a little bit, and maybe in the plane's Transform Scale component, I am just going to make that a little bit bigger.

So that will at least give the character something to walk around on. So to make this character interactive, I am going to look in that Standard Assets folder that we imported, and I want to grab this ThirdPersonController script, and all I need to do is just left mouse click and drag, just drop this right on my game character and I am going to get this warning about losing Prefab. I am going to go ahead and Continue. It's okay. Basically, this is breaking the connection between our character model that's in the Project folder and kind of making a local copy that's just going to be used for this scene.

So I will click back in the hierarchy on our game character and I should see here I have got a couple extra components that I can see in the Inspector. So I have this Character Controller and this Third Person Controller. Both of these are scripts that are now attached to this game character. So I am just going to make a couple of adjustments here. Let's start by looking at the Character Controller. I'm just going to set some scaling here, and again, this might be different if your characters are slightly different size.

So basically what I'm doing here is forming sort of a rough shape that will represent the collider of my character. So this is going to kind of flesh out the rough physical shape and sort of help out with physics calculations that Unity will do during game play. So now let's move on to this Third Person Controller script and let me just expand that. What we want to look at here are these Animation Clips. So we've got the Script asking us for an Idle Animation, a Walk Animation, a Run Animation, and a Jump Pose.

So what I can do is look back to my Project panel, find that game character file, and I can see here I have got the animations that I've set up through my FBX Importer, and what I can do is just click and drag those over. So I am going to set the Idle Animation for Idle Animation. Walk for the Walk Animation and so on for Run and Jump. And there are a few other settings here as far as the Maximum Speed that the character can walk with, how high it's going to jump.

I am just going to leave these on defaults for now. One additional thing I want to do is add a light in my scene, so if I switch back to the Game view, let me just move my camera so I can see. So I want to just place that a little closer. Let me click here. I will click and rotate. Let me adjust this.

And I will click and drag this. So if we switch to Game view, I can see my character is very dark and that's because there are no lights in the scene. So I am just going to go ahead and add a directional light, so I will click GameObject > Create Other > Directional Light and then that will add this Directional Light to my hierarchy and let's go ahead and rotate this. Let me zoom in a little here. So I'll just rotate it so it's kind of shining on our character and if I switch to the Game and I can see that lighting looks a lot better.

So let's go ahead and click Play and we should see that our character has some interaction. So by clicking the A, W, S, and D keys, I should be able to make him walk around. So let's go ahead and click Play and see what that looks like. Okay. So I am clicking W here to walk forward, S to walk backwards, and I can turn using A & D. And if I hold down Shift, I can make him run. And I can jump with the spacebar.

So those are kind of the basics of using a script to add interactivity to your game character. In the next video, we will cover getting the camera to move around and follow the character as he walks and runs around.

Show transcript

This video is part of

Image for Game Character Creation in Maya
Game Character Creation in Maya

40 video lessons · 9304 viewers

Chris Reilly
Author

 
Expand all | Collapse all
  1. 3m 50s
    1. Welcome
      39s
    2. What you need to know before watching this course
      1m 9s
    3. Understanding game asset creation
      1m 21s
    4. Using the exercise files
      41s
  2. 25m 35s
    1. Setting up scene folders (Maya and Unity)
      3m 58s
    2. Optimizing geometry
      3m 14s
    3. Using symmetry
      4m 8s
    4. Extruding geometry
      4m 19s
    5. Sculpting geometry
      4m 1s
    6. Importing reference sketches
      5m 55s
  3. 37m 14s
    1. Modeling the head and nose
      5m 34s
    2. Creating the mouth
      4m 28s
    3. Crafting the eyes
      5m 11s
    4. Building the body and a wing
      10m 11s
    5. Forming the limbs
      8m 5s
    6. Adding finishing touches
      3m 45s
  4. 36m 11s
    1. UV mapping overview
      2m 43s
    2. UV mapping the body parts
      9m 18s
    3. UV mapping the face
      7m 40s
    4. UV mapping wrap-up
      3m 44s
    5. Mirroring
      4m 57s
    6. Texturing
      2m 46s
    7. Normal mapping
      5m 3s
  5. 46m 21s
    1. Setting up the skeleton
      5m 19s
    2. Building the spine
      3m 39s
    3. Finishing the skeleton
      4m 32s
    4. Rigging the legs and feet
      8m 35s
    5. Rigging the torso
      3m 49s
    6. Rigging the arms and hands
      3m 35s
    7. Rigging the face and head
      5m 9s
    8. Rigging wrap-up
      2m 27s
    9. Skin binding and weight painting
      5m 26s
    10. Animating in Maya
      3m 50s
  6. 29m 9s
    1. Exploring the Unity interface
      3m 3s
    2. Importing character and animations into Unity
      5m 50s
    3. Controlling animations with scripts: Third-person character controller
      7m 14s
    4. Controlling animations with scripts: Third-person camera controller
      4m 4s
    5. Making read/write animations using UnityScript Editor
      4m 8s
    6. Controlling scripts with animation events
      4m 50s
  7. 19s
    1. Additional resources
      19s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Join now Already a member? Log in

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Game Character Creation in Maya.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.