Humanoid Characters in Unity | Scott Onstott | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

73 Lessons (6h 13m)
    • 1. Welcome

      1:21
    • 2. Creating characters with Adobe Fuse

      9:16
    • 3. Auto-rigging with Adobe Mixamo

      2:45
    • 4. Applying animation to rigged characters in Mixamo

      2:45
    • 5. Applying animation to rigged characters in Mixamo

      2:57
    • 6. Importing an Autodesk character into Adobe Mixamo

      2:27
    • 7. Selecting and animating a fantasy character within Mixamo

      4:02
    • 8. Exploring commercial rigged and animated characters

      2:55
    • 9. Using Unity Hub to install the Unity Editor

      5:33
    • 10. Configuring Unity's user interface

      3:34
    • 11. Importing and setting up an architectural model

      6:43
    • 12. Importing selected standard assets

      5:22
    • 13. Rendering lightmap data for static objects

      4:54
    • 14. Configuring packages

      2:32
    • 15. Creating Cinemachine virtual cameras

      7:46
    • 16. Importing a character into Unity

      6:07
    • 17. Combining texture maps in Photoshop

      8:41
    • 18. Shaders and render modes for eyes and eyelashes

      4:48
    • 19. Configuring hair material and texture maps

      4:37
    • 20. Combining textures with alpha channel using Gimp

      4:36
    • 21. Exploring an avatar's bones and muscles

      4:54
    • 22. Referencing a controller in the animator component

      6:33
    • 23. Controlling the character with scripts and components

      7:14
    • 24. Altering code to make the character walk by default

      5:58
    • 25. Altering the script to walk and not run diagonally

      5:04
    • 26. Set up Cinemachine FreeLook camera

      3:08
    • 27. Fine-tune free look rigs

      7:24
    • 28. Replacing animations in controller

      6:52
    • 29. Integrating a death animation into controller

      7:23
    • 30. Scripting death by falling

      5:01
    • 31. Walking up stairs using colliders from hidden ramps

      5:12
    • 32. Bringing in a new character

      3:31
    • 33. Designing a third person player gameobject

      6:19
    • 34. Connecting FreeLook camera to third person player

      3:26
    • 35. Swapping out characters within the third person player

      3:03
    • 36. Using legacy characters

      6:05
    • 37. Using high quality commercial characters

      7:09
    • 38. Making character prefabs and overrides

      5:43
    • 39. Using the Cinemachine collider extension

      5:49
    • 40. Setting up post-processing and anti-aliasing

      4:10
    • 41. Configuring post-processing effects

      5:36
    • 42. Commercial animated stationary characters

      7:26
    • 43. Custom animated stationary characters

      5:51
    • 44. Providing seating for an animated character

      4:28
    • 45. Cropping an animation on humanoid rig

      6:11
    • 46. Bring in a new character to be driven by Ai

      4:09
    • 47. Configuring components on Ai character

      4:14
    • 48. Building and refining the nav mesh

      4:36
    • 49. Getting agents to climb stairs

      3:28
    • 50. Creating off-mesh links

      2:52
    • 51. Making nav mesh obstacles

      6:25
    • 52. Implementing high-cost areas for the Ai

      5:42
    • 53. Abstracting NPC for use with other skins & avatars

      6:14
    • 54. Outlining the goal of the game

      2:57
    • 55. Getting the NPC to chase the Player

      3:17
    • 56. Getting a hold of the Player's Animator through code

      7:41
    • 57. Logging NPC's collision with Player to console

      5:59
    • 58. Stopping the NPC and killing the Player

      7:03
    • 59. Offsetting the death animation

      2:58
    • 60. Allowing NPC to take leap with off-mesh link

      6:33
    • 61. Adding user interface with canvases and buttons

      8:33
    • 62. Toggling defeat canvas on when NPC collides with Player

      3:55
    • 63. Differentiating between victory and defeat in code

      9:17
    • 64. Refining the NavMesh for fluid Ai movement

      3:24
    • 65. Building a GameManager class and game object

      8:19
    • 66. Connecting Restart buttons to setting bool Property true

      4:37
    • 67. Connecting controller and testing in game

      1:17
    • 68. Mapping the Fire2 axis to run

      6:46
    • 69. Mapping the Fire1 axis to crouch

      4:42
    • 70. Mapping analogue stick to Cinemachine FreeLook camera

      4:47
    • 71. Fine tuning how analog game stick controls camera

      4:46
    • 72. Building and playing standalone game

      4:39
    • 73. Next steps

      1:02
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

149

Students

--

Projects

About This Class

In this course you'll learn everything you need to know to create a simple puzzle/chase game employing a third person player character that you control and an enemy non player character that's controlled by an artificial intelligence.

This course is for beginners who either have no experience or may have dabbled in Unity with characters and want clarity on how character creation, rigging, animation, finite state machines, character controller components, custom C# scripting, game controllers, Cinemachine, post-processing and much more comes together to make a playable game.

All the software that I use in the course is available free, including Unity personal edition, Microsoft Visual Studio, Autodesk Character Generator, Adobe Fuse, Adobe Mixamo, and free samples from RenderPeople. I happen to use Adobe Photoshop in some lessons but I also show how to use Gimp, which is free.

Coordinating all of this is actually a lot easier than it sounds! I'll take you step by step through this wide collection of topics and tools in the course of building a simulation which eventually evolves into a simple yet entertaining game.

To take this course all you need is a Mac or a Windows computer. Let's get started!!

Please download the exercise files from this link and extract them to your Desktop for use in this course.

Meet Your Teacher

Teacher Profile Image

Scott Onstott

Technologist, Trainer and Author

Teacher

Hello, I'm Scott. After some years helping to design buildings (mostly corporate interiors) early in my career I decided to specialize in teaching design software to architects, engineers, builders and now maybe you too! I have taught more than a thousand students face-to-face and my video courses have millions of views across the many platforms where they are published. I've written 23 books in all, and 14 of them are on computer software. My websites are www.scott.training & www.secretsinplainsight.com

 

See full profile

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Welcome: Hi, I'm Scott on stock, and I'd like to welcome you to humanoid characters and unity. In this course, you'll learn everything you need to know to create a simple puzzle Chase game, employing 1/3 person player character that you control in an enemy non player character that's controlled by an artificial intelligence. This courses for beginners who either have no experience or may have dabbled in unity with characters and want clarity on how character creation, rigging, animation, finite state machines, character controller components, custom C, sharp scripting game controllers and much more comes together to make a playable game. The software that I use in the course is all available free, including Unity, Personal Edition, Microsoft Visual Studio Code, Auto Desk, Character Generator, Adobe Fuse, Adobe Mix, Imo and Free Samples from Render people dot com. I happen to use a W Photoshopped, but you can use any image editor in the course, including gimp, which is free. Coordinating all of this is actually a lot easier than it sounds, but I'll take you step by step through this wide collection of topics and tools in the course of building a simulation which eventually evolves into a simple yet entertaining game. To take this course, all you need is a Mac or a Windows computer. Let's get started. 2. Creating characters with Adobe Fuse: in this video, I'd like to discuss how you can generate characters using auto desks. Solution the character generator. Now Autodesk is the manufacturer of three DS Max and Maya, and you can use these high end programs to generate characters. And the advantage of doing it that way, of course, is that you can make any type of unique character, and you can clothe them anyway you see fit. However, these methods require an inordinate amount of skill, and usually that skill level isn't in just one person. This is usually in a team one personal focus on modeling the skin. Another one will rig the character. Another one will texture map it and so on. So this is a high end solution. So I think Autodesk created the character generator so that anyone without those skills can create characters, and you can do this for free. Or there are some paid options within the software. So to get started for free, just create a free Autodesk account. Once you do that, you can then sign in and all this type of my credentials here and sign it that will take us into the software itself, and then I can create a new character, and over here we have a kind of wizard like interface where we have to make choices, and there's the first choices thes style. And we're going to start with a standard character if you want to use these other characters, their premium and that means that you have to pay for them. That's indicated by this symbol in the corner. So I'm going to stick with Standard and then down below. Here we have premium and standard offerings, both female and male, and these offerings here are not the final product. You can customize any one of these characters, these air, just like the jumping off points. So let's say I'm going to create a new character that looks something, something like Alice, and then I'll click on customize, and they were taken into a new environment where we can customize her face. And so the way that this entire interface works is it works with these blend shapes. Historically, an older term for that is morph targets. The idea is we have two different models that were blending or morphing between, so you just strike the slider to the left and then it would be this model. If you drag it to the right, it would be this model. So somewhere in between is a blend. You don't have to be satisfied with just that binary choice along the slider. You can say All right, Well, I kind of like it a little bit more over towards the Trinity side of the street. But I don't like her nose so you can click on the nose down here, and that brings up another blend and you don't have to use the same models. You can look for a model in here that has a knows that you like, say I like Debbie's knows. So when a drag Debian and I can replace either one of the models, seven are replaced Trinity with Debbie. And then the blend is just between these two characters for the nose. Nothing else. You can see how the nose is actually affecting a little bit of the area of here as well, but it's basically the changes air confined to this area, and you can see that in the graphic Here. I want to go with a slightly smaller nose. And as you can imagine, you can change any other of the features of the face. By doing the same type of thing, I'll go to the next item here. The skin this is allows us to change, to choose the skin color and for some reason, these air premium offerings up here and down here their standard. So we could see what she looks like with dark skin, and we can see what she looks like with some kind of alien skin. So this is simply changing the texture map associated with the character. There's a longer list, and some of these say one of three. In a case like that, what you can do is click on show variations, and then you can try these different variations. They have different amounts of makeup on, and then I'll go ahead and go to the next item, which is eyes, and it works in a similar way. We'll choose brown eyes and then I'll go for hair, and there are lots of different hair styles to choose from. See what she looks like with one of these hairstyles, and if I just click on it, it will just take the default color. But if you go with show variations. You can then scroll through the list of different hair colors. Let's see what she looks like with black hair. And then I can go for the body and customize your whole body in the interface is just like the face interface. But now we're thinking of her whole body. And so let's see if we just drag between these two default characters at the top. There's one that's or heavyset, one that slender and I can come through here, choose different models to blend between. Let's see what she looks like with Barbara instead of Venus. And then I can blend between the two. And, of course, you can customize the different aspects of the body moving on. You go for clothing and you can choose her outfit. Let's say we want her to look like a business person and the scroll down and find something that looks suitable. It's more evening where there's even hospital gear. Want to go with, um, maybe something like this. It's a show variations and see what she looks like in green. Okay, and then we can go for the bottom and again, you can have fun dressing her up. However you like I'm gonna go with maybe a longer skirt and then the shoes and you can choose some other footwear for her. See what she looks like with something like this? Pretty simple. Now, finally, we've come to the end of our custom ization process. So when she gets the new shoes, I will click finish, and then you need to name the character and click OK, and then she'll show up in your list of character designs right here. Now I've made a couple of characters that I had to pay for here with the symbol here. Now May is going to be free. She doesn't have that symbol. The next step is to click on generate character, and if you ever wanted to go back, you can go ahead and edit the character right here. But I'm gonna go ahead and generate that character, and now we need to specify some of these details so you can output in different resolutions . I wanna keep it free, so I'll use the low resolution and you can set the character height either in centimeters or inches. Let's say she's a little shorter than that. Let's say she's She's 64 inches high, and I'm going to output close a speculum app and a normal map. I don't want facial expressions. You'd have to use a plug in and unity to animate character talking. It's better to output quads over triangles if possible, So I'm glad we have that choice. Over here we have different output options. I'm going to uncheck, generic and check unity there no options for unity and then generate. It'll just take a few moments for this fbx file to get created. And once it's done, we'll see a little green badge on generated characters over here. Okay, now I have the new generated character. I can click on that over here, and then I can download this right here. And then it will come down as a zip file containing the fbx file that I can later import into unity. 3. Auto-rigging with Adobe Mixamo: now that I've completed a character infused, I would like to rig it, and that means I'm going to send it to mix Imo Super easy. To do that, you just have to click this button and then you're prompted to give the character name, which I already did when I saved the file in the previous video. I'll just say Save here and then it's going to export the model to a temporary file and then upload that to the mix Imo server. In this case, it's about a 10 megabyte file that gets uploaded, and then it opens up. Mix Imo in the auto rigor, so rigging means adding a skeleton inside of the skinned mesh that we generated infuse. And this skeleton will have joints, which are already configured to have limited range of motion so that it works just like the human body. And once you have the rig connected with the skin, you can then apply animations to the character. So mix Imo is really great time saving feature, because if you were going to rig this yourself in three DS max or Maya, it would take a great deal of skill and time already were able to see this character being animated with this little clip here that comes in by default. So we're gonna disable the facial blend shapes because we're not gonna animate her talking . And then over here, you have a choice of the skeleton level of detail. I'm gonna go with the standard skeleton that has 65 bones and I'll say, finish, proceed with this new character. So there's only one character that can be active in mix Imo at any given time. So you have to say, Yeah, go ahead and use that character and then you have a choice. You can either download the file in t pose or you can animate that character, and we're gonna actually do both. In this course, I want to start by downloading the T pose character. And over here you need to change the format from the generic FB X to the one that's configured, especially for unity. And then the pose is gonna be either t pose or the original pose this actually, the original pose and the tipos air the same in this case. But you can import models from other software and they might not, might not initially be in t pose. But here we go. I'll download this standard pose so that tipos means that the character is standing there and their arms are stretched out. And so their body makes something like the letter t. So now we've downloaded that fbx file In the next video, I'll show you how you can animate the character that we've imported into mix Meow. 4. Applying animation to rigged characters in Mixamo: now that I've completed a character infused, I would like to rig it, and that means I'm going to send it to mix Imo Super easy. To do that, you just have to click this button and then you're prompted to give the character name, which I already did when I saved the file in the previous video. I'll just say Save here and then it's going to export the model to a temporary file and then upload that to the mix Imo server. In this case, it's about a 10 megabyte file that gets uploaded, and then it opens up. Mix Imo in the auto rigor, so rigging means adding a skeleton inside of the skinned mesh that we generated infuse. And this skeleton will have joints, which are already configured to have limited range of motion so that it works just like the human body. And once you have the rig connected with the skin, you can then apply animations to the character. So mix Imo is really great time saving feature, because if you were going to rig this yourself in three DS max or Maya, it would take a great deal of skill and time already were able to see this character being animated with this little clip here that comes in by default. So we're gonna disable the facial blend shapes because we're not gonna animate her talking . And then over here, you have a choice of the skeleton level of detail. I'm gonna go with the standard skeleton that has 65 bones and I'll say, finish, proceed with this new character. So there's only one character that can be active in mix Imo at any given time. So you have to say, Yeah, go ahead and use that character and then you have a choice. You can either download the file in t pose or you can animate that character, and we're gonna actually do both. In this course, I want to start by downloading the T pose character. And over here you need to change the format from the generic FB X to the one that's configured, especially for unity. And then the pose is gonna be either t pose or the original pose this actually, the original pose and the tipos air the same in this case. But you can import models from other software and they might not, might not initially be in t pose. But here we go. I'll download this standard pose so that tipos means that the character is standing there and their arms are stretched out. And so their body makes something like the letter t. So now we've downloaded that fbx file In the next video, I'll show you how you can animate the character that we've imported into mix Meow. 5. Applying animation to rigged characters in Mixamo: so following on from the previous video, where we imported a character into mix Imo and rigged it. It's now time to animate that. So when you click on animate over here and that will take us into this other part of the interface in mix Imo. And so here's our character that we imported earlier in T Pose, and you can navigate in here by dragging the mouse to move around. And you can also roll the mouse wheel to zoom and hold down the shift key and drag the mouse wheel to pan. So it's very intuitive. Now, over here we have ah whole extensive list of animations, and you can search this list appear by tart typing in a search query. So, for example, let's say we want this character to have a death animation of some kind. So type in death enter. There's lots of different ways to die and their animations in here that I'll do that. So if I can click on any one of these, it will apply that animation to this rig, and you can see what's happening. This one isn't really appropriate for what I want to do it. You have to be holding a rifle. Basically, I want a death animation where she falls from some kind of height and she follows forward. What I want to do is actually search a little bit more. I'll say Death forward, and then we can try standing death forward one. Now that one looks a little weird where she's kind of hunched over for a second. I don't think that looks so natural. What about falling forward? Death? Now that works, but she kind of falls on her side. How about this one here, standing. React to death. I'll go with this one, all right, so you can adjust the animation a little bit here if you want to, and you can trim or crop the frames as well. I'm happy with the way this looks, though, so I don't need to make any tweaks, and I'll just go ahead and download that. And then we're presented with the settings, So I want to download that as a fbx for unity file. 30 frames A second is right. I don't need the skin because I already downloaded this character in T pose, so I don't need to bring in the skin again. I'll say without skin, I just want the animation. You can optionally add key frame reduction to simplify the animation, but we can also do that in unity. So I'm gonna just say none here and download. And that's going to download an fbx file that also contains the name of the animation. In it, it's Nicole at Standing React death forward dot fbx. 6. Importing an Autodesk character into Adobe Mixamo: Fuse and mix Imo were initially developed by the same company, namely Mix Imo, and both were bought out by Adobe and configured into their ecosystem. But fortunately, mixing mo is kind of an open system, and it allows you to import characters that you have generated in other programs so I can go ahead and upload a character right here. And then you can just drop Dragon drop a character into this box. Earlier on, we had generated a character using auto desks character generator and that we downloaded a ZIP file. So I'm going to extract that here and that will have a fbx file right there. So then I'm going to move this over so I can see that box and I'll just drag and drop this fbx file in there. It will upload it and rig it just like it did for the native Fuse asset. But this time it's an auto desk character generator asset, and as you can see, it's already rigged and animated so I can go next and then we have to say next again and it's applying that same death animation. But I don't want that animation on here. So what I'm going to do is go right up to the U. R L and get rid of all this stuff after the domain and press enter, and that will take us back to the initial state of the character. And then I can go ahead and download that in T pose. And I want to set the format to Fbx four Unity and download that character in t pose. So now this character will have a rig that means it will have a skeleton inside of it. And that's something that isn't the case when you just download it from auto desks. Character generator. So this will be much more useful to us in unity now that it is rigged just for clarity. I think what I'll do is go ahead and rename this one, not just one, but I will get rid of the one and call it rigged. Then I know the difference between these, and if I look at details on that, you can see that it's just slightly larger in file size to accommodate the skeleton 7. Selecting and animating a fantasy character within Mixamo: In addition to being able to rig an animate characters in Mix Imo, it also comes with its own list of characters. And you can see here that we have a long list of characters to choose from, and it goes on for a couple of pages. I'll choose one of these characters and have a look at it. So one of the great things about these characters is that they are unique characters that you wouldn't be able to create using Autodesk character generator or Adobe Fuse because they have elements such as this robotic arm and clothing, which is unique. So the of course, you can model anything you want in three DS, max or Maya. But this requires specialized advanced skills that not everyone has. So it's nice to be able to access some of these fantasy characters and cartoon characters from this list without having to have the skills to generate them from scratch. So I'm going to look through here and find a character, maybe some kind of medieval character. I'll go with this, Dre are, and feel free to choose your own character. Don't feel that you have to choose the same one that I did. So I'm gonna use this guy. But let's say I wanna add an animation to him. I'll go back to animations now. And I think it might be amusing if we had this guy in a business meeting some of the type and meeting. And then there's two clips that come up and I'll use the male version having a meeting. And let's just have a look at what this animation does. So he's just sitting there for a while. But as you'll see, he does different things. He waves his hands about it. Looks like one hand might be on the desk, the other hand on his knee talking, gesturing. And if you just wait a little longer, you'll see he does some other stuff so we don't have to use this whole clip. We can slice it. See, now he's typing on a keyboard, so he just wanted to have him do that. You could just use that section of the animation of his hands were resting together. Now he's talking, so there's a lot of different things in this one clip that we might be able to use in different contexts. So I'd like to get this whole clip, and then we can make those creative decisions about cropping in unity. Of course, you could do that here as well. You could make these sliders come in a little bit tighter together, and you can trim off part of the animation. Another thing you can do here that's very useful is character arm space. So if I change that value, you'll see that his arm is going to go up higher. So this would accommodate a higher table. And so this is a way of adapting this animation clip to whichever character that you happen to choose. If I had a different character, maybe their arm would appear a little bit higher or lower. And so this is a way that you can configure that and adjust the animation clip prior to export. Once you are satisfied, you can go ahead and download that and let's download that as an FB X for unity. 30 frames a second. We need the skin, so we need to say with skin and you optionally can reduce the key frames. But we can also do that immunity. So I'm gonna say none here and leave that up to unity to optimize. So go ahead and download that, and it's going to use the file convention of the character name at the animation clip name . So here's the character name at having a meeting comma meal. So there you have it another way to get characters and animations out of mix Imo. 8. Exploring commercial rigged and animated characters: in addition to the big software companies character generating solutions, There's also commercial humanoids that you can purchase, and one good source is render people dot com. They claim to be the world's largest library of scanned three D people. So the advantage of using these models is that they're Rio people in the real world, and their physiology was three D scanned as well as texture mapped from life. So these air going to look very realistic. So one thing you can do is purchase, but you can also get a number of free models. So I'm gonna try that get free models and they're different categories of free models. They're free for commercial use, no registration required, so you can get three deposed people. Now. These don't have rigs, so they're just going to be static. This is equivalent to architectural entourage from the days of static architectural illustration, so these can just dress up your illustration if you don't plan to animate it now in unity. Of course, I want to have an interactive simulation, so I don't really want those static people. Instead, I'm more interested in these three D rig people, so they already have skeletons inside of them. And that's what this is showing here in the graphic. That's a skeleton. And so we can download these. I'm gonna say, Choose your format and I want unity. And then it just downloads that as a zip file scrolling down. There's also some three D animated people. Now these aren't coming in in t pose, so they're much more difficult to use for some other purpose. But what they can do is add lifelike realism to your scene with these people that are just on a loop, they're just doing a certain animation. So I'm not so sure about this guy, But I think this model will look nice in our scene. She's just gonna be in an Idol loop where she's kind of shifting our weight and standing there, and so that could be a nice form of dynamic entourage. Again, I'll choose my format, and in this case we don't have a specific format for unity. So fbx is the way to go. Fbx models store not only the skin and the textures, but also potentially any blend shapes and animation clips that are associated with model. So it's kind of the lingua franca of humanoid models. So I just wanted to point out that we can get a few free models here, and then you can also go ahead and shop for people, and you can look by topic and you can purchase these people if it makes sense for your project. 9. Using Unity Hub to install the Unity Editor: ID like to show you how to install unity and configure it for this project, so you can begin at unity dot com, and then you could get started and then you'll choose a license type. If you make less than 100,000 U. S. Dollars a year, you can use the personal version, which is free. You go ahead and download the unity hub and install that and that looks like this. So go to the installs tab here and then click on add, and then you'll need to select a version of Unity. And for this class, I recommend using this version right here. 2019.1 point three F one. These versions here are beta and Alfa versions, and it's likely that when you watch this course, there may be additional versions of unity that are available. But I recommend going back and installing this particular version so that we can all be on the same page and then click next. And then we're going to install the native support on your platform. So if you're on Windows, you want to install the universal Windows platform, build support, and you'll also need the windows build support down below. If you're on the Mac platform, you'll choose theme AC Build support. And if you're on Lenox, of course, you'll choose this one. I'm on Windows, so I'll choose these options. Also, install the documentation. It's always helpful and say Don unity Hubble get started downloading that and installing it . And when it's done, this progress part will disappear. After the install, it's finished. Go to the project's page and click new, and we're going to make a three D project. We're gonna call it humanoids, and we're going to specify a location for that somewhere. I'm placing it in my documents Unity 2019.1 folder, and I like to put the unity version as a folder. That's not necessary. But if you do that, then you can keep track of the version that you created your projects in. So I'm going to click create, and it will get started launching the Unity editor and creating the folder structure for a standard project. By default, you'll have an assets folder, and in there will be a scenes sub folder. If you click on that, you'll find an asset in here. This is the sample scene and its path is listed down below. It has a dot unity file extension. The sample scene is listed here in the hierarchy, and if we expand that, you'll see that it contains the main camera and a directional light in the file system. This is represented here in the Project folder Humanoids, and in there you'll find a number of folders, which are necessary for the operation of the editor. Generally, you don't want to mess with these files with the possible exception of assets. So if I go into assets, you'll find the scenes sub folder. And there's also a meta file here, which is used for version control. We'll go into the scene's folder. That's where you'll find the sample scene asset, which has the dot unity file extension. So this is what actually contains that camera and the light. It also has a meta file associated with it. I like to make a change to hide the meta files on my system, and this is just a personal preference. But if you want to take this advice, I will show you how to do it. So I'm gonna go over to edit project settings editor version control mode. I'm going to change that from visible meta files to hidden meta files. Note that you can also specify version control systems in here, but I'll change it to hidden meta files. And then, if I go back into the file system, you'll see that those meta files are gone. Now they're still there, actually there, just hidden. But I find that that makes my file system a bit cleaner. I'd like to make one other change here in the project settings before I go, and that is all. Click on the player and change the color space from Gamma Tau. Linear linear color space generally looks a lot better, but at the expense of greater demands on the player. So if you're building to Mobile, you should stick with gamma. I'm going to build to the Windows platform so it's a computer, which should be able to handle the linear color space. We'll close the project settings and also let's take a look at the preferences and go to external tools. And here you can set up the image application that you'd like to use with unity, and I have photo shop installed, so I specified where that waas and also just a matter of personal preference. I like to use visual studio code when I program, rather than the standard visual studio. Either compiler will get the job done. I like code because it's a bit lighter. Weight launches faster. I like the colors better. But again, that's just a personal choice. Here's where you specify all the programs that are external to the unity editor, so I'll just go ahead and close that. And in the next video, I'll show you how to configure the user interface here in the editor to suit our project. 10. Configuring Unity's user interface: ID like to show you how to rearrange the user interface, and this is really a personal preference issue. A lot of people have a certainly out that they are accustomed to and feel free to use it that way. But in this course, I'm going to set it up in a particular way. So if you'd like, you can follow along with me and save a custom layout just for this course. So one thing that I don't like in the standard layout is the fact that the game and the scene are adjacent to each other. There are many occasions where you want to see what's happening in the game and the scene at the same time, So I like to drag the game window out of there and drag it over here next to the project window. And then I'll resize this border between these and I'm gonna also stick something over here . Normally, the inspector is on the right. I don't like to have it over there because there are many occasions where I want to drag things from the project window into the inspector, and so it's difficult when it you have to go all the way across the U I. It's going to drag the inspector over here and place it adjacent to the game and next to the project window like this. I'll just resize some things. I'd also like to have something over here on the right so that my aspect ratio isn't so wide on my game window over there. I'm gonna put the console because it's helpful to have the console visible while you're playing the game and not hidden over here behind the project window. It's also a good idea to put pallets that have a vertical aspect over here. So, for example, we're going to need to look at lighting settings from time to time. I'll drag that and put it next to the console, and we're also going to need the AI navigation window when we're building that functionality into our characters, and I'm gonna place that over here is Well, I'll go back to the console and then make this narrower. You can always resize it when you need it, and I'm also going to drag this separator so that we have about half of the window devoted to the scene and about half of it to the game and I'll just line this up. So this division lines up with the division above and over here, you can also rearrange the border between the folder view and the asset You over here, you have a slider that controls the size of the icons. I like to drag this all the way to the left so that you see the icon and the name together in a list. So I think this is the way I want it. Maybe there's one other pallet that I want up here. Yeah, I would like to have the animator which is useful when we're looking at finite state machines, and that just appears up here by default. I'll just drink that over like that. So the assets stores on the right, and now I think I'm happy with the layout, so I'll go ahead and save that over here by opening up this drop down menu and choosing save layout, and you can call it whatever you want. You could give it the course name. I'm just gonna call it my layout and click save. And so now I could go back to the default layup and then any time I can pop back into my layout so you can have multiple layouts to suit different tasks that you perform in the editor. 11. Importing and setting up an architectural model: in this video, we're going to bring in some architecture that the characters will ultimately explore and walk around on. And that's in the Exercise Files folder. There's an fbx file here called Architecture, so I'm going to move the Windows Explorer out of the way and then dragged the architecture fbx file into the Assets folder that makes a copy of this file in the Assets folder. If I click on that, you can see in the inspector that it has all these properties. I'm going to scroll down in the model tab here and turn on generate colliders, anticipating that the characters are going to have to walk on this object so they need to be able to collide with it. Also, we're going to want to generate light map you weise so that we can bake lighting into this mesh. I'll click apply to get this into our scene. I'm going to drag it from the project window into the sample scene, and so now we have an instance of this object here. So when that instances selected you see it has a transform. When you want to get the properties of the model, you have to actually select the asset here. So now whenever you bring in an asset, you can frame in on it by double clicking on its icon. And it's a good idea when you bring in something for the first time to make sure that it makes sense that it's at the right scale. An easy way to verify that is to create a cube. The cube comes in by default with a scale of one, so it's a cubic meter. We can reset the transformed by clicking the gear icon, and then I'll zoom out by rolling the mouse wheel, and you can see that that cube is a lot larger than the architecture. That means that the architecture is way too small, so I need to go back to the asset here and change the scale factor. I suspect that if I uncheck convert units, that will fix the problem, because I generated this model in sketch up where I set the units two meters. So there's really no reason to convert the units here, so uncheck that and click apply and that automatically propagates to the instance which is in the scene. I'm going to zoom out by rolling the mouse wheel, and you can see now that the architecture is coming in at the right scale, this makes sense. This is a cubic meter. Now I can erase this cube, which is really no longer needed. The next thing we need is a ground plane so that the characters can walk around on something and not just fall when the game begins. So I'll create a ground plane by going up to the hierarchy menu. Create three D object plane and it just coming in at the center of the scene. So whenever you create something, it's always a good practice to immediately reset the transform. I'll come over here and click the gear, and she was reset, and that zeros out the position of the object. 2000 So now this is actually in the right location to navigate in the scene. Window dragged the right mouse button to move around like this. Drag the mouse wheel to pan, enroll the mouse wheel to zoom, so that is looking at the right in the right location. If you really want to verify it, another way is to use this system. Appear where you click on one of the cones to look at the model dead on. And then we're in perspective by default. So if you click on the word back, it changes the camera into Ortho graphic mode so that it's really like an elevation and you can see that this object is right there precisely in the right location. I'll click on the word back again to switch back into perspective, and then I'll just navigate over here so I can see the whole complex. Now the ground plane is too small. By default. I need to change that. Let's change the scale in X and Z to 100 and 100. Unity has a Y up co ordinate system. So why indicates the vertical direction here indicated in green. So by scaling it in X and Z, we ended up making a ground plane that extends well off into the distance. I'd like to stay organized in the Assets folder here. As we move forward, we're going to be creating a lot of folders and files. So to stay organized, I'm going to create a folder in here called Models Thinking ahead. I know I'm going to have character models and architecture models so I could create sub folders in there. I'll make one called characters, and then I'd like to go back up to the Models folder. So I'm going to click on that right here to make sure I'm in the right folder and then create another folder in there called Architecture. And if you go into one of these folders, you'll see these kind of breadcrumbs up above telling you where you are, and you can navigate by clicking these items in a similar way. You can navigate over here by clicking on the folders. So if I want to get the assets that I have right here in the root of the Assets folder into the right sub folder, I can drag it from here over here and drop it. So now that architecture model is in the architecture folder, another thing we can do here with this architecture model is go to the Materials page. There's no rig or animation to speak of with this particular model, but there is a material so I can go over here to materials and then extract the materials, and it will extract it into the folder that you're currently in, which is architecture. So I'll select that and there's the material. If I select that, it's actually an asset on disk this asset, I'll just drag the silver and you can see its name is grid box. Underscore default dot matt. So that's a material file, and its properties are listed here. It's just about as basic as you can get. It's just a single white color. 12. Importing selected standard assets: at this stage, I would like to import the standard assets, and they used to be available from the assets menu. They were part of the editor, and now the decision has been made to move them to the assets store because they're no longer being updated. However, they're still very useful, and I think it's one of the top searches in the asset store. So I'm going to locate the Unity Technologies standard assets and then download and import them, and that will decompress the ZIP archive. And in a moment it will show us a dialog box with all of the potential assets that we can import from this package. And here it is. So I'm going to start by checking none. And then I can be selective about what I want to bring in. I know I don't want any of the sample scenes all collapse that, and then within the standard Assets folder, I don't need anything that's just too d. I don't need the cameras characters. No, Within this, there are some useful scripts that were going to use will collapse first person in roller ball characters and then I'm going to bring in everything having to do with the third person character, and then I'll collapse that. I know that some of the scripts in there a reference cross platform input. So if we don't want to get errors, we need to import that as well. And we need this cross platform input as well. We don't need the water editor, though, so I'll close that you don't need effects or environments, fonts, particle systems, physics materials. I would like to use some of the materials that come with the prototyping, though, so I'm going to select the materials. I don't need the models or the pre fabs or the Shader, but I will take the textures. We have some utility scripts here that I think it would be safest if we just import them. I'm not sure if the scripts reference any of the utilities, and we don't need any vehicles. That brings us to the end of the list so you can click import to get those items into your project. It's going to create a folder over here under assets containing all of that information, and it will also have to compile the scripts that we're bringing in, so it should just take a moment and there it is. So now, over here in the console, we have a lot of different warnings, but no errors. And if you read the warnings, they refer to things like the build target is obsolete. These air older targets that have been removed. If you go down, you'll just find that all of these things refer to either build targets that are obsolete or code that is also obsolete. That means it still works, but it isn't really current. And that's fine because we're really not going to use all of these assets that we imported . I'll clear the console and go back to the scene. Now, to take advantage of some of those assets, I'd like to change the material of the ground plane, and we have a nice material here under prototyping that has a grid on it. Navy Grid. I'm gonna drag that material and drop it onto the plane. And already we have a better looking situation. Now we have something competing here, though we have a grid and we have the navy grid. So I'm gonna go over here to gives Mose and open this up and turn off show grade, and then we have a Navy grid which is currently very large. You can see it's really, really big. What I need to do is go to Navy Grid here in the standard assets and scroll down and change the tiling to a greater value. Let's say it's 100 X and y So now we have smaller grid squares. I think we could go even another order of magnitude up, so I'll go back there and make this 1000 by 1000. See if that took Zoom in closer and it looks good. Now we have smaller squares, which makes sense for this scale of the project. We had to use such a high tiling value because if you recall, the plane was scaled up so much. I'm just gonna rename this to ground plane and also save the scene as. And I'll place that in the scene's folder. So instead of calling it sample seen, I'll just call it Main, and then I can go to this scene's folder over here and actually just delete the sample scene, and now we're set up a little bit more so we have a more attractive looking environment to place the characters in 13. Rendering lightmap data for static objects: Now let's consider the environment and the lighting. First of all, the scene is illuminated solely by a directional light. We'll select that in the hierarchy. The thing about directional lights, which is unique to that this type is that the position of the light, it doesn't matter at all, so I can move this light around anywhere I want, and it doesn't change anything. So it's convenient sometimes just to move the directional light up and out of the way kind of to simulate the sun. It's up high somewhere where it is doesn't really matter, and it doesn't represent where the sun is in the environment. What is significant, though, is the orientation of the light, so you control that by rotation. So if I rotate this, I immediately get visual feedback here in the scene. And that's because I'm showing lighting appear. This light bulb is on. If it's off, the results from that are not shown, so I need to turn that on, and then I can see the lighting. So when you rotate this around and tell, the stairs are visible because they have little shadows in front of them. That means that the light has to kind of be angled back a little bit. And you could just play around with this to find some interesting light angle. I kind of like this one because we're getting a shadow in here. That's kind of dividing the surface. We're also seeing the stairs. So in the settle on that, I'm happy with that orientation. Now, next up, let's consider the environment that is the sky in the way that that looks. So what I can do is go over to the root of the Assets folder and right click and say, create material and I'm gonna call this one skybox, so I have the skybox material, but I need to configure it as such. So I need to start by changing this shader to a skybox Procedural. This shader controls the way the sky looks. But to reference this, we need to bring it into the lighting. So I need to go over to the lighting tab. And right now we're using the default skybox. So I only use my custom skybox here instead. And then the dragon drop that over here into this lot. So now the customs skyboxes operative, and that's what we're seeing here with this Grady int ramp of sky color down to the horizon through the game window. This is visible through the camera here. So if you want, you can move the camera around and you can see that that is showing us different results. Here. I'd like to change the way the sky looks so going to go back to my sky box material. And then I can change exposure, which is how bright the sky is. We'll make it a little darker or brighter. We can also change it's parameters and see that we can get something that looks more like a sunset or sunrise by changing the atmosphere thickness. I'm just gonna make a couple of tweaks here, so it's not just the standard sky. It's a little bit different. I'll look over here in the scene, see that we have kind of a glow going on. Okay, so now I've kind of set up my lighting. I have directional light and I have a skybox. Both are responsible for the environment lighting, and now that that's true, I can go ahead and bake lighting into the architecture. So in a select the architecture and it has to have light map. UV has already generated for this process to work. If you recall when we first brought this in, let's go back here and select the asset we selected to generate light map. You've these here, so what this does is it adds another channel of texture coordinates for the object it's called UV to. And that's where we store the rendering information in the form of the light maps, and you can store a real time in baked light maps. We're gonna be doing that and to kick off that process, all we have to do is select the object in the hierarchy and make it static. And if you just check static that that's enough to do it and you're prompted. If you want to enable the static flags for all the child objects as well, you say yes, and that kicks off the rendering and you can see that happening down here because there's a progress bar happening and you can start to see there's little subtle changes that are happening here to the surfaces, and this will further change as the process continues 14. Configuring packages: in this video, I'm going to configure the packages that are used in this project. So I'll go up to the window menu and open up the package manager. This opens up a separate interface that lists all the packages that I have installed after a moment after checking for all the available packages. List them. So I know I'm not going to use ads in this project, so it comes preinstalled. I'm going to just remove that is to clean up my project a little bit and keep it a streamlined as possible. It has to remove files and folders and re compile. And when it re compiles, we get the same warnings from our standard assets so you can feel free to clear the console . After that happens, I'm going to remove the analytics library as well. I'm not gonna need that here. And I'm just gonna clean this up a little bit more. I'm gonna get rid of in app purchasing. She comes pre installed. You definitely don't want to get rid of the package manager. You Why? Because that is, in fact, what we're looking at right now. So we need that. And down here I'm gonna turn off unity, collaborate, which is useful if you're working in a team, I'm not going to need the unity timeline in this project either. So this removed that as well. Now I am going to want Sina machine, so I'm going to select that and click on Install. You should just download the latest version of Sin the Machine, whatever that happens to be at the time when you're taking this course right now. For me, it's 2.3 point four, but it's likely that this will be a different version for you. And then we also need the post processing stack, and that's right down here. I'll install that as well. So this package manager makes this very easy. It used to be you'd have to go onto a website, download the files and install the manually, and this makes it far easier and more convenient to stay up to date. Once everything is compiled, you can clear the console, enclose the package manager. It's taking a moment here to download and install the post processing she eaters and to compile those. Okay, so now I can clear the console and closed the packages window 15. Creating Cinemachine virtual cameras: in this video, I'm going to discuss Cinema Sheen, and we'll create a couple of virtual cameras to get started. Before we dive into that, though, let's examine what we have already. We have a main camera, so select that in the hierarchy. The main camera in The Inspector has a transform, as all game objects do. The transform gives it a position, rotation and scale in three D space. And that's what we're seeing here with this gizmo. We're seeing the transform, and we can move that around and reposition the camera. As I move that around, you can see in the game window that we're actually looking through that camera. If I scroll down here in the Inspector, you'll see that this camera script has different controls, such as field of view. I can change that to make it more wide angle or more telephoto, and it also has numerous other parameters that you can configure. We also have an audio listener by default, which is how we can hear sounds in the game. They have to go through the audio listener, which is analogous having an ear that makes sense to have your eyes and ears in the same location. So that's what we're getting here with the camera in the audio listener components. So that's how it set up. Normally by default, as you create a more complex game or simulation, you'll probably wanna have multiple cameras. But each camera that you add has an overhead associated with it. 55 cameras in my scene. Each one has to continuously calculate a lot of information, and so that takes a hit on the frame rate of your game. One of the great things about Sina machine is that you can have many different virtual cameras, and they're all past into the main camera. And that means that there isn't a hit on performance because there's really just one main camera in the scene that has to be calculated. You can have as many virtual cameras as you want, and Sina Machine is great at blending between those virtual cameras when needed. So to get started with this, just go up to the center machine menu and create a virtual camera, which is the simplest type. As soon as we do that, several different things happen. The first thing I notice is that we no longer really see the architecture in the game window, and that's because the virtual camera was created in the center of the scene wherever that happens to be. So if I scroll up here, you'll see that we have these strange coordinates as the position, and that's just happens to be at the center. So what I can do initially is reset the transform to the origin point, and then, in this case, that's right on the ground plane. So I'm going to move that up by dragging the green arrow up a little bit, and then I'll move this back so I can see more of the architecture. So this works very much like the main camera, however, were now controlling the view in the game through the virtual camera, And I also noticed that we have this little symbol, which is the centre machine icon next to the main camera. So if I go to the main camera and scroll down here, you'll find we have a new component that was automatically created. It's called the Sina Machine brain, and you only need one brain in your game. The brain is the control center that interfaces between all of your sin a machine, cameras and the main camera. So the brain has just a few different parameters, and I'd like to make one change here. I'm gonna turn off show camera for us TEM. But first, what is the first time it's this these white lines that we see her in the scene? If I d select by clicking over here in this white space in the hierarchy, the frustrate miss still visible and that shows us the field of view. But if we add multiple send machine cameras, that gets to be a little bit crowded. So what I like to do is God going here uncheck show camera for us TEM. And then when I d select those white lines disappear in the scene. I just find that to be a little cleaner, but this is entirely optional. Now I'm going to go back to the cinema sheen camera, and if I move that around, it's making a change in the game. If I go to the main camera and try to move that around, you'll see that you can't move it because it's transform is now being controlled by the sinner machine virtual camera, and it's doing that through the brain, this brain redirects all of that information to the virtual camera. So, for example, if I go to the main camera and trying to change something about it, let's say I want to change the field of view. I'll try dragging that. Try changing the number here. It doesn't work that's now controlled over here in the virtual camera. So if I want to change the field of you, I have to do that here can do that. And as I do that and change that number by dragging left or right on the word field of view , the number will change and we can see the results are changing as well in the game and also in the scene with the red Frustrate him. I'm going to set that at D five. Okay, so now we have a virtual camera and it's being fed through the main camera through the brain. Let's create a second sin. The machine camera. I'll go up to sin machine, create virtual camera again. So now we have B cam to and V Cam to has a different point of view. It's in a different location in world space. I could move that around, I could rotate it and create a very different point of view as compared to the first virtual camera. And now how do we get between these two different virtual cameras? They're both being piped through the main camera through the brain. But what controls which camera is visible in the game is the priority and the order in the hierarchy. So right now, this is the last item in the hierarchy, and that's what we're seeing in the game. But I could go back to V. Cam one and say Solo, and then I would look through it in the game window. But that's something that you can only do here in the editor. I can turn that on and off to look through it, and that's helpful when you're designing the game. But if you want to have this camera take over, you can change its priority value. So right now it's 10. If I have a value higher than that, then this will take the priority salts that change that to 11. And now we're looking through this camera, prioritizing it over virtual camera to even though virtual Camera two comes later in the hierarchy doesn't matter because the priority value is higher on virtual Camera one, this is generally how Sin Machine is set up to work. 16. Importing a character into Unity: Now that we have a couple of virtual cameras to work with, I'd like to bring in the first character. I'll switch over to the file system and let's bring in the first character that we rigged. That would be Nicole. That's the Nicole dot fbx model. So what I'm going to do is go to my Models Characters folder and then Dragon drop the Nicole dot fbx in there that will copy that asset into this folder. Now I can select that, and I can see it here in the Inspector. And in this preview window, I can drag and look at that a little bit, and I'm just gonna drag this preview window down to the bottom. And then we have these different tabs appear that we can configure in a moment. But first I'd like to bring that model into the hierarchy by dragging and dropping it from the project window into the hierarchy window. And then this appears at the origin point. I prefer to do it that way rather than dragging it into the scene window, because if I could do that, I could drag this into the scene. But then it's going to appear at some arbitrary and location. You want to delete that when you drag it into the hierarchy. It comes in at the origin point, and the origin point is very useful. When you're configuring a character, you should leave that area open so that you can work in that area. Now I'm going to go into one of the virtual cameras. It's a virtual camera, too, and I'm going to increase the priority of that camera. Let's say 2 12 So we're looking through that, and I'm just going to move that over and rotate that camera so that we're looking at the character and I want to get a close look at that character here. Another way that we could do that is we could just navigate without the camera we could navigate. He's in the traditional tools with the mouse. I could just navigate here in the scene and get a look at that character, and then I could select the virtual camera here and go up to game object, align with view, and that will move that virtual camera into the same position that we're looking at in the scene. So now I can move in the scene and you can see that that virtual camera is in that location looking at the character, and that's what we're seeing here in the game window. Obviously, we have some issues that we need to correct with the characters appearance. First of all, it's all white. We need to worry about materials, and we need to consider the shade er's as well, because some of this is partially transparent. It's were actually seeing the eyeballs floating here on the face. So we'll get to that in due course if I want to adjust the model, I need to go back here to the Nicole Asset, and then I can go ahead and make any adjustments here. So for a character, the character is going to be moving and we're going to be creating our own collider for the third person character. So we don't want to generate colliders from the MASH itself. That would be computational e expensive because this has a very unique shape, and that shape is actually gonna be changing over time, so we don't want to do it that way. Another thing we don't need here is a light map. You've ease because this is a dynamic character is gonna be moving, so we don't want to have light maps because that would only be appropriate for static objects. So we don't need to really make any changes here. And it came in at the right scale. This looks to be in the right size in comparison with the rest of the architecture. That's human scale. Next up I'll go the rig and the animation type is set to generic by default, and that's not what we want. This is a humanoid, so we're going to change that to humanoid here, and we want to create the avatar from this model and then say Apply. That will create a new asset here. If I expand Nicole, you can see that there's many different sub components here, including the Nicole Avatar. The Avatar is a necessary part of this in order to animate the character. This particular fbx file doesn't have any animations associated with it. So here on the animation page, I don't need to import any animation. I'll uncheck that and say, Apply for the materials. We want to extract any embedded materials and you can see down here there are a number of different materials slots that are part of this model. And right now it just says none over here because we don't have any material assets to assign to these. So what I need to do next is, say, extract materials and you're prompted to place it in the same folder where the asset is. That's a good practice, so I'll say Select folder and that will create these new material assets right in here. And then once the materials are in there, it will automatically remap them so the proper materials are mapped to the materials in the asset of the same name. And then we also need to extract any textures that are part of the fbx file. So I'll click, extract textures and also place those in the same folder. And then in a moment we'll see all the all the different texture maps come in. But there's a lot of configuration that we have to do, and we'll get started with that in the next video 17. Combining texture maps in Photoshop: Now that we have extracted the materials and texture maps that came with this fbx file, it's time to start configuring them. I'll begin with the body material, so select that here as an asset. And then over here we need to change the shader from standard to the standard speculator set up. And I know this because the texture maps that come with the model are separated into do these different maps diffuse gloss, normal and opacity. So gloss is also known as smoothness, and that is part of the speculator set up Shader You can see down here we have a smoothness , parameter or gloss, and so this is the closest shader that would support this type of compartmentalization, of texture maps. Another thing is that the rendering mode right now is transparent, and that's not correct. We need to change that too opaque, and that immediately has an effect over here in the game. We no longer see those eyeballs kind of floating in the middle of the face because it's no longer transparent. We're actually seeing the surface is now, and I'd like to get even closer to that. So I'm going to select the virtual camera and go into local mode and then just move that a little closer in the blue direction to the face and all this. Get a better look at that here in the game window. So we have some configuration to do to get the texture maps to appear here. I'll go back to the body, Matt, and we have different slots or channels that the Shader supports, including alb Edo speculator and normal. And we're going to be using these texture maps in those different channels. But first we need to combine some of the texture maps because the way that unity works is the albedo color is like the diffuse map in three DS max. It's the most important component in the shader, and that would be through the RGB channels. That would be what we're seeing here with the diffuse map. But we want to get the transparency information, also known as opacity in the Alfa Channel, and so we're going to need to use an image editor. To accomplish that, we need to combine the diffuse and a passive the maps into a single file that has an Alfa Channel. So what I'm going to do is just double click on this diffuse map to launch that in my default image editor, which is Photoshopped. And then I'll go back into unity and double click on the opacity map and bring that over and what we're looking at here are the eyelashes, and so they're partially transparent. What I need to do is have this a pass ity map become an Alfa Channel of this image. So the way that you do that in Photoshop is you select the diffuse image over two channels and create a new channel, and that's called the Alfa Channel or the first channel beyond RGB. And so right now it's black. There's nothing to it. I'll go over to this image I choose, select all or press control a and then I'll copy that to the clipboard. And at this point, I can actually close this image now that it's on the clipboard and then here with the Alfa Channel selected, I'll choose Edit paste. So now that information has been transferred here into the Alfa Channel, so this image contains this information. In addition, it has all the RGB information, and you can show them simultaneously if you turn on this little eyeball here to show the Alfa Channel. But that's not necessary. It's just a way to visualize it at this stage. I'm going to save this as, and I need to save it in a format which supports an Alfa Channel. Not all of the formats do. I'll just stick with the native Photoshopped format, and I'm in that same folder right now. There are no Photoshopped files in that folder. What I'm going to do is rename this and call it diffuse underscore capacity. That way I know that has both of those channels in the same file, and I'll go ahead and save that and then close this image. When I go back to unity, we should see a new item here appear. And here it is. I believe, let's move this over a little bit and you can see there. That's the new one. And now I need to get this into the right channel of my material. We'll go to the body, Matt, and then I'll drag this and drop it in the albedo Channel, and now we can see her skin and all those facial features show up next. We need to worry about these speculator and smoothness components. So some of these files here have the word speculator, and there isn't one that says smoothness. But that's what Gloss actually is. So the way that this works in the material is the Speculator Channel is the RGB, and the smoothness or gloss is the Alfa Channel. So I'm going to double click on the Speculator file here for the body, open that photo shop and then I'll open up the gloss file and photo shop. I'll just put those side by side and then I'll press control a for select All control. See for copy. We'll close this window without saving. We'll make a new Alfa Channel and then paste Control V and then I'll just save it directly as. And I'll rename this speculator underscore Gloss, and I'll save it as a Photoshopped document. Enclose that back to unity. We have a new item here, right here. We'll go to the body, Matt, and I'll drag this new Photoshopped document in there. It looks good. Now it's something funny is going on with the eyes which will solve in another video. But for now I'm just configuring the body. Matt and we have just one other item to attend to, and that's the normal map. This will add more detail to the surface, and we have a normal map right here that we can use. However, this normal map hasn't been tagged as such, and unity needs you to come in here and change the texture type from default to normal map , and then you have to click apply. And so now Unity understands that this isn't just a regular texture map, but it's actually conveying the normal information that I can go into the body. Matt and Dragon drop this into the right slot here, and if you look closely now, we have much better and more realistic. Sheeting on the surfaces were starting to to see her bone structure and such through that normal map. And so these are the different steps that we have to go through for each one of the materials. And after you do that, you can actually come in here in a race. Some of these files, because we already have the photo shop document here that stores the diffuse and the opacity. So there's really no reason now to keep the diffuse or the A pass ity maps around something to delete those. And then we also have the speculator and the gloss in this one file so I could get rid of these two. And that just simplifies things a little bit here in the asset window. So I need to have these three different texture maps associated with the body map material . 18. Shaders and render modes for eyes and eyelashes: in this video, I'd like to focus on the eyes and the eyelashes, which don't look good right now. I'd like to get closer to those. So I'm going to select virtual camera, too, and I'm going to just navigate here. And this icon is so large, I'd like to change that by going up to gizmos and un checking three D icons. So now it's a more reasonable size. I'll just move this camera in and maybe rotate it. Just get a better view here so we can focus on the face. This move this over and just framing on that face a little bit closer. Okay, so let's work on the eyes next. So right now we have the Nicole instance here and I'll expand that and you can see that it has different parts. Has the body itself the bottoms, which is the genes or pants? The default, which is actually the eyeballs, eyelashes or separate Harris separate. There's also shoes and the tops, which is the shirt. There's also this node, which has a disclosure triangle next to it, and if you start opening this up, you'll find that that has a very complicated structure. That's related to the Avatar, so we don't need to get into that right now. Instead, I'm concerned with these two nodes default in eyelashes and what I'd like to do is rename default and call it eyes. And if I do that, that occurs as an override on the prefab. So if I select this instance here Nicole in the hierarchy, you'll see that there's an overrides dropped down here and it says Nicole Eyes So Eyes has been overridden in the prefix in the prefab because it's been renamed. Okay, so now let's go ahead and create a new material for the eyes. And I'm going to base that on the body Matt that I've already configured. So I'll select the body Matt, and duplicate that by going up to the edit menu and saying Duplicate, which is controlled the and then in the new duplicate material. I'm gonna rename that and call it eyes, and then I'm going to drag the new eyes material and drop it on the eyes object here so it assigns that to that particular object in the hierarchy. So now I can make changes over here, and we should see the effect in the game window. I'm going to change the Shader from the standard speculator set up that we needed on the body to the more typical standard material. And as soon as I do that, we can now see the eyes texture map on there, and this has a metallic property, and so the eyes need to be somewhat metallic in order to reflect the environment. And then you can increase the smoothness value to control how much of that environment reflection is visible in the eyes. Typically, you wanna have them be very smooth, so I'm increasing that to a value of, let's say, 0.93 and you can start to see the environment. They're reflected in her eyes. There's the horizon line there, and we're seeing a little bit of the yellow of the sunrise or sunset there on the horizon. You can just vary these parameters, and you can see that the eyes look much more interesting when there's a metallic value that's around, Let's say 0.6 or so, 0.62 I think that's the best balance point. Let's create another material based on eyes, so I'm gonna select that impress control de to duplicate it there are renamed the new material eyelashes and then drag and drop that new material onto the eyelashes. And then we can make changes to this now. So I'm going to change the rendering mode from opaque to fade. You might think transparent is the right one, but transparent reflects the environment, whereas Fade does not. So I'll choose fade and that looks much better. So the eyelashes fade out according to the Alfa Channel, which is what we created here in the albedo map, if you recall in the previous video. 19. Configuring hair material and texture maps: will work on the hair next, and I'd like to get a better view of that in the game window. I'll select the virtual camera and just move it up a little bit in the scene. Actually, I'm I've got the main camera selected, so it's not moving. I need to explicitly select the virtual camera number two. And when I want to do is get kind of a 3/4 view of the hair. So I see more of a side view. No, this rotate that a little bit here. Okay, Now, I'd like to go ahead and configure that, so I'll select the hair, Matt, and I'll just scroll down here. I'm going to lock the inspector so I can keep this information in the Inspector lock that right here and then over here in the project window, Aiken DoubleClick on the diffuse map with hair to open that in photo shop. And I'll go back to unity and open up the hairs capacity map. And I'll just configure those here side by side. So I'm going to select everything in the opacity map by pressing control A for select all control C two copied to the clipboard control W to close the window, and then I need to click over here in the channels palette. I need to click on the new button to create an Alfa Channel and then control the to paste. And then I'll save that as, and I'll just append underscore capacity to the file name. I'll save it as a PSD. And then I can close this and I'll go back to unity. And then we have a gloss and a spectacular here, so I'm going to open them both. I'm going to select them both and then right click and choose open to open them both simultaneously here. So we have gloss and speculative glass will act like that smoothness, and that will be the Alfa Channel. So I need to select all copy to the clipboard, close the window, making Alfa Channel paste that in and save it abs spectacular underscore gloss, and I can save that and then close back to unity. And then there's also a normal map, which I'll have to tag later. So let's configure this by changing the shader to the speculator set up, and the rendering mode will be opaque. Actually, the rendering mode won't be opaque because it does have an Alfa Channel for opacity. So I'm going to change that to fade because I don't really want the hair to reflect the environment, so Fade is a better rendering mode. Then I'll take the diffuse a pastie map here, drag it and drop it in the albedo slot, and then I'll take thes speculative gloss and put that in here, and then I'll take the normal to put that in the normal map slot. The normal app doesn't really do anything yet because it's not marked as a normal map, but you can actually fix that right here in the material. I can just say fixed now, and it updates, and I have completed the hair and I can come in here and just clean things up by erasing certain maps in here that I no longer need. I'm holding down the control key so I can make a discontinuous selection, and then I'll delete these items. I should be left with these combined maps that I have been Photoshopped format as well as the normal map. And then I'll unlock the inspector and you can see in the normal map that it's properly tagged as a normal map here, so proceed in this way and I'll leave it up to you to configure the top and the shoes and the bottom on your own, now that you know these skills of combining texture maps and assigning them to the various channels of the materials. 20. Combining textures with alpha channel using Gimp: Now, I'd like to show you how to combine images in gimp so that one image becomes an Alfa Channel on the other. So, for example, here we have the hair and it needs this treatment so that the capacity map becomes the Alfa Channel of the diffuse map. And I've already installed gimp, and I need to let Unity know that I'm using it. So I go into edit preferences, external tools, and then right here you can find the gimp, execute herbal, and now Unity will understand. When I double click on a texture map, it will open it in my chosen editor. I'm going to control, select both of these items and then right click and choose open. And that will pass both of these texture maps over to gimp directly. So here they are in gimp. Here's the diffuse texture map, and here's the capacity map. So our job is to make this a pass ity map in Alfa Channel in the diffuse map, we'll begin by selecting all and then choosing edit copy to copy that to the clip word. Then I'll go over to the diffuse map, and then I'd like to get a look at what's happening in the channels here, so I'm going to go to channels and pull that out and expand that. And then I'd like to also see this a little more clearly. So I'm going to configure this tab and change the previous size two gigantic. So we have the RGB channels in there and they'll be certain situations where you'll also see an Alfa Channel up here. And let me just show you that. For example, if you see this situation, were you seen Alfa Channel here? This is actually not the Alfa Channel that you want. If it shows up in this top area, it's kind of for the internal use within gimp. What we need to do is get the Alfa Channel down here in this lower section, have it actually act as such in other programs. So if you see an Alfa Channel up here, what you can do is right. Click on the layer and say, Remove Alfa Channel and then create your own Alfa Channel down here in the lower left hand corner, click create a new channel and then call that Alfa and make sure that the fill opacity is all the way down zero by dragging this over and click. OK, so that creates a real Alfa Channel down here in this lower section. Now, remember, we still have the opacity map on the clipboard. So with this selected, I should be able to go up to edit paste and have that come in. However, there's an additional step here which can be very confusing in gimp, and that is that we have a floating selection up here, which is the pasted layer. I need to get that tow. Actually, go on the Alfa Channel now. So the secret to doing that is to go up to layer and say anchor layer, and that will get rid of that floating selection, and it actually anchors it here on the Alfa Channel. So now we have the image as we need it. I'd love to file export as, and I'll select a file type by extension scrolling down. I'm gonna find Photoshopped image and the file name up above. I'm going to append with underscore opacity and then export that switching back to unity. We should see that appear right here now. No, I need to get that on our character so I'll select the hair object, scroll down in the Inspector, and then there's the albedo channel. I'll drag this over here and drop it in the channel and make sure you're rendering mode is set to feed. If it's a pink, then you're not going to see any of that transparency that we just built into the Alva Channel. So you have to change this to fade, and then you'll see the hair is partially transparent in the areas to find in the Alfa Channel. 21. Exploring an avatar's bones and muscles: after you've configured all the materials and texture maps that govern the skin of the character, it's time to go deeper and explore the avatar, which is where the skeleton is located. So this character has a rig associated with it and that rig. It contains an avatar. So if I go here to Nicole in the assets holder, I can go to rig. And here's where we have an avatar definition that's created from the model based on the humanoid type that creeds this item here. If we open this up, you'll see there's an avatar in here. Note that there's no avatar in the hierarchy, so we have these different nodes here that correspond to these nodes. There's also meshes in here that contain the actual geometry of the skin. But it's the avatar that I would like to focus in on now. And so what we need to do in order to configure that is we need to save the scene first and then configure the avatar because the avatar is actually a separate seen. That opens up when you click on that, and now we're looking at the avatar configuration, and you can toggle off the scene lighting. And so now what we're looking at is the relationship that the skin has to its skeleton. And part of the genius of this system is that the animation clips that you apply to your character controller are actually animating the avatar. And the avatar is this layer of abstraction between your character and the animation clips . And so the Avatar has a mapping here. There's a symbol of the body, and there's a mapping between the actual objects in your model. In all, the objects in this particular model are prefaced with the word mix Imo Rig and these air mapped to the various items in the Avatar, which are always the same no matter what character you use. And what happens in the animation and in the controller is it animates these components here in the Avatar, not the specific components in your model, and that the great thing about that is it allows you to swap out different characters very easily because all of the animations apply to this standardized avatar and the only really work well when the characters in T pose here. So what can happen? It's not present in this particular model but it it happens quite frequently, is that the skin will be slightly out of alignment with the skeleton. That can happen. See if this bone right here, for example, is rotated a little bit. If it's like that, you'll get these warnings. Character is not in T pose, and it will indicate which items need your attention shows in red. That's what you can do down here. It's a pose enforced T pose and Unity will try to rotate all of these bones as needed to maintain t pose. And that is the standard position that your character has to be in to match up with this avatar. And then what I can do here is, once it's in t pose, I can go over to muscles and settings, and then I need to apply any changes that I've made. In this case. I'm just going to revert. They didn't really make any meaningful changes. Now, in the muscles and settings area, we have these these different ways. We can deform the body by moving the skeleton around, and we can check it out and see if the mapping between the skin and the skeleton is good and one way you can visualize. Visualize that it's just by doing these different transformations on the body and making sure that it kind of works well, this should be fine. I don't think we need to change anything in here, but I just wanted to show you that you have all of these very settle controls that you can adjust in here, too. Control the way that the muscles connect the skeleton to the skin. And as I said, I don't need to do anything here. I just wanted to show it to you so you can explore it. I'll say, Done. And that will take us back to our original scene. In the next video, you'll see how we can animate the avatar by using an animation controller. 22. Referencing a controller in the animator component: after you have explored the Avatar, it's time to control that avatar. And so we'll go over to Nicole in the hierarchy and you'll see that there's an animator component which is automatically on this instance, and this happened as soon as we brought this into the hierarchy, it automatically added this. This component is the bridge between the avatar, which exists in the model and the instance, which exists in the hierarchy and in the scene. The avatar is controlled by a controller, which is right now it says none. So we need to either create a controller from scratch or reference, one that already exists to save a lot of time. I'd like to you reference the third person controller that comes with the standard assets, and I can find that here by drilling down into the standard assets third person character animator folder. And there you'll find the third person animator controller. I'll drag and drop that into this slot. Now I'd like to explore what that controller is all about. So to do that, I'll go over to the animator window and you can find that under window animation animator not to be confused with animation animator window shows this type of interface, which reveals what is called a finite state machine and by default, it's a little confusing because thes nodes could be reorganized. I'm gonna pull this over here like that. It doesn't really matter where they are, and this machine is entered here through the green node, and it goes right away to the orange node, which is the default state. This particular state is called grounded, and it's actually in this case, it's a blend tree. You can see that here in the Inspector, and you can go into a deeper layer by double clicking on the grounded node that opens up the blend tree. And you can roll the mouse wheel and drag the mouse wheel to navigate in here. So the blend tree is this thing here. If I click on that, I'll get its properties in the inspector and there's a graphic here. It shows the different clips that we can blend between. If I scroll down here, there's a whole bunch of different motions that are associated with that, and up here, it's going to have it has two parameters turn and forward, which is how we control the character and control the avatar, and we blend between these different animations. So in the very first motion here is humanoid Idol, and I can see that here in the blend tree, right at the top, There's humanoid Idol and that is located right here in this fbx file. On disk. It's in the animation folder, and in there you'll find this animation clip called Humanoid Idol. So this clip is animating an avatar, and we have an avatar on our character because the avatars air always the same. The animations are reusable, so this humanoid idol clip Let's let's take a look at that. I'll drag this up to get the preview window and I can play, And then I can actually navigate in here and zoom in. You can see the default character is this guy in a black and white jumpsuit, and you can see the animation. There is just showing the character kind of shuffling their weight between their two legs, kind of going back and forth a little bit. So that's the Idol state. Let's take a look at another animation clip, for example, Humanoid walk. I'll click on that here in the blend tree and you see that over here that's located here on disk in this fbx file. And this clip looks like this where the guys walking along so the blend tree can blend between all these different motions where they're walking or running or turning. And this is all happening in what we call the grounded blend tree. I'll go back up to the base layer, and there's additional blend trees for crouching or airborne when the characters jumping. So, for example, I'll double click on Airborne, and there's a different blend tree in here that has different animation clips. So there's really a lot of complexity that's built into this controller. We can just use it out of the box without any modifications. I just wanted to let you explore this and see how this is brought together. Now, the way that we get between these different states is through these arrows, and if you click on one of them, you'll get the parameters for that over here. And if you scroll down, you'll see that this is controlled by a condition. When Crouches crew so crouches a parameter over here, and when that's true, the flow will go from grounded to crouching, and then it will start blending between these crouching clips. But all of this is built in to the standard controller, so we don't really have to worry about it too much. But we just need to avail ourselves of this functionality. So if I go back to Nicole here, we've done what we need to do just by referencing that controller, and that's actually bringing together all of these different clips that exist within the standard assets. Later, I'll show you how we can swap out some of these clips to refine the motion and get it the way that we want it to work in the next video show you how we can add additional components to our character that will actually let us use this animator in our game. 23. Controlling the character with scripts and components: At this stage, we have an animation controller referenced in our animator component, which is on our instance here in the hierarchy. In order to use that controller and drive it with the keyboard, we need to have a script that connects the keyboard to the controller. And we can do that by using one of the scripts that ships with the standard assets. So I'll go to the scripts sub folder here under third person character, and you'll find three different scripts the AI Character Control, which will cover later, and two different third person scripts. There's the third person character and the third person user control. So I want to use the third person user control, and I want to get that on to my character. So if we select the character in the hierarchy and scroll down here and drag this third person user control script and drop it right here, when this turns blue, we get a warning that says cannot restructure prefab instance. Children of a prefab instance cannot be deleted or moved, and components can be reordered. You can unpack the prefab instance to remove its prefab connection, and that last sentence is the key here, so it's not letting us do what we want to do. What we need to do is break the connection now with the prefab, and we do that by right clicking on the instance in the hierarchy in choosing unpack prefab . What happens is the icon changes. It's no longer blue with a little file icon. Instead, it's just white. We still have the same child objects we no longer have override over here because this is no longer an instance of that prefab. It's its own object in its own right. However, the animator component still references the Nicole avatar, which is part of that prefab. So that is our connection, and that's all we really need. We don't have to have this whole object be a prefab. We just need to reference the Nicole Avatar, which is part of that prefab. And if I click on this, you'll see that it selects that here on the disk. So this Nicole Avatar is part of this prefab or model. So now I can go back to the scripts folder where I was before, and that now I can go ahead and successfully drag and drop the third person user control script and drop it right here and it will apply. Not only does the user control come in, but it has certain dependencies that are brought in as well, namely a rigid body, a capsule collider and also the third person character script, which is right here above it in the standard Assets folder. So we have 123 and four different scripts that are applied here just by dragging one over. We need each one of these in order to control our character successfully, so we just need to configure this a little bit and then we'll be often running. All we need to do really is configure the Capsule Collider to match the shape of the body. So right now the capsule is it has a height of one meter. We need to match it closer to the character. Let's say it's 1.8 meters, and when you do that, you'll notice here in the scene that the capsule seems to stick below the ground. That's because it's centered here at the bottom of the feet, right on the ground plane. So after we set the height, we need to re center that by specifying a coordinate and why That's half the height or 0.9 meters. And so now that capsule is tall enough. If you want to be even closer to her head that this see this is a little bit higher than the character we can do is adjust the height. Let's say she is not 1.8. She's 1.7 meters high, and that would mean that half of that is 0.85 and that's a little better. It's closer to her head. I'd also like to change the radius of the capsule, make it a little smaller, maybe around 0.33 or so 32 And that has a volume which represents the characters body. And this capsule collider is what actually collides with geometry in the world that has other colliders on it. Okay, And what we need to make sure is that the ground plane has a collider on it has a mesh collider on it. So when we play the game, I would expect that these colliders interact so that the character just won't fall. She'll just actually stand on the ground plane, So go back to that character again. So she has a rigid body, which enables physics calculations to be performed on the character capsule is what controls that interaction. The third person character script has different values for how fast the character moves and turns, and so on. One thing I want to change here is the ground check distance. I'm gonna increase that 2.3, and then I'm gonna play the game and let's see if it works. I'll click play. And first thing you might notice is that I have a green color that appears over most of the screen. And that's just a visual reminder that I've set up to let me know that I'm playing the game . And the reason for that is any changes that you make while playing the game or lost when you stop playing the game. So I like to know for sure that I'm in play mode and I set that up by going into preferences, and I'll show you that in a minute. But right now you can see that what while I'm playing the game, the character is in the idle animation. She's shuffling or weight back and forth thing one leg to the other so it's actually working. We, the controller, is doing that and through that grounded state, if you recall, and now when I use the keyboard, use the up arrow and she's going to run away from me. I'll use the down arrow on the keyboard. She comes back. I'll use right arrow or left arrow, and in this way I'm able to control the character. Incidentally, you can also use the W A S D keys if you prefer to use your left hand on the keyboard and keep your right hand on the mouse, so that's entirely optional. So now we're able to control the character, and it takes all of these different components to make that happen. I'll just show you finally, get out of play mode by clicking the play button again, and I'll go up to the edit menu and go under preferences. And here's where I set up the green color under general play mode tint. You can choose whatever color you want. I recommend a bright color will get your attention 24. Altering code to make the character walk by default: If we play the game right now and control the character with the keyboard, you'll find that she runs everywhere she goes. If I hold down the arrow keys, she runs everywhere. If I hold down the left shift key and use the arrow keys, you'll find that she walks. So in this game, I want her to walk by default, and only when I press either one of the shift keys I want her to run. So I need to make a change to the code to make this happen. So I'm going to scroll down in the Inspector and locate the third person user control script. This is the interface between the user and the controller. I'm going to edit that script by opening up the gear icon and choosing edit script from the shortcut menu, and this will launch your default compiler and I'm using visual studio code, and I don't expect that you know C sharp, but I'm just going to make a few minor changes to the code that you can follow along with. Even if you're not a programmer, this will be a good way to get a taste of how programming works. Gonna scroll down here. It's a fairly short script, and the section in question is right here, where we see it, says in a comment. It says walk, speed, multiplier. And what this says is with, if not mobile input. The exclamation point means not so if it's not unmovable, it means we have a keyboard and we can have a shift key in the first place, and that is the case in this game. So this says, if the input is basically the left shift key, then we're going to multiply the move parameter by 0.5, which slows it down to a walk. What I want to do is have it so that if it's not, if we're not pressing the shift key, it's going to walk. So one thing I could do is just invert that by putting an exclamation point just in front of the word input. So if it's not holding down, if you're not holding down the left shift key, then you'll be walking by default. If you are holding down the left shift key, we're going to run, so let's go ahead and save this and then go back to unity and test it out. I'll play the game, and now I'm going to press the up arrow key and she's walking, not running. If I hold down the left shift key and pressed the down arrow, she's running. She's running everywhere. When I hold down the left shift key, when I let go of the left shift key, she walks, so that's an improvement. There's still some other things I want to do, though. Let's go back. Let's get out of play mode and go back into the code editor. And then one thing I can think of is I want her to to walk. Unless I press either shift key, left or right. That's what I can do here is add some white space after the not and I'm gonna put a parentheses around this statement, and then in this area, I'm gonna put an or symbol in the or symbol is two pipes, two vertical bars or also known as Pipes. And then I'm going to copy this code right here to the clipboard. I like that control, see, and then right over here on the pace that in, and then instead of saying left shift and have, it's a right shift. So either way left or right, and we're gonna say not on that. And let's see if that works. I'll say that, and then I'll go back into unity, and it automatically compiles that script. And when it does that, sometimes you'll get a listing of any warnings that you have in your entire project. This case, we're getting those old warnings from the standard assets, which I can clear. And then I'll play the game. And now, if I hold down the right shift key and walk around, she's walking. If they let go of that, she's walking. So something is not working right. I'll go back into the code editor and trying to debug Lis just by reading through my code. I made some kind of logical error her, and I think I know what it iss. We need to put parentheses around these two or statements because we want the not to apply that either one of them, not just the 1st 1 I can then get rid of this white space in between the parentheses and then save that we'll go back into unity and play. This is a quite a typical example of this process where you'll make on error of some kind. You have to debug that. Go back and fix it and keep trying until you get it right. So now when I just use the arrow keys without holding any other keys down, she's walking. If I hold down the right shift key, she's running. If I hold down the left shift key, she's running. It works as I wanted it to. 25. Altering the script to walk and not run diagonally: when I play test the game, I noticed that the character walks by default, which is good. And if I press each arrow key individually, she walks. However, when I press to arrow keys simultaneously, she seems to run, and we need to see if we can fix that in the code. So if I can identify why that's happening, I'll go over to the third person user control script that we edited earlier. And if you're called when we edited this, we added the ability to press either shift key, left or right. And what this says is, if it's not left or right, then we're going to assign a value of 0.5 to move. So we're slowing down the move to have speed, which essentially makes her walk. And so the member variable move is what is being changed to control the speed of the movement. And that is of the type Vector three. Vector three is a simple data type that has three different numbers. Three floats representing typically the X, y and Z coordinates. So, looking at the code, I noticed that there is a m underscore move here, and this is the addition of these two components, and I suspect this is where the problem arises. Let's just see if we can try to understand what's happening here. So this this first component is multiplying the V value times This member, variable cam forward and V is to find appear as a float. It's getting input from the user from the vertical axis. And what that means is, it's the up or the down arrow keys. In the case of a game, which is based on a desktop platform, and the horizontal axis is the left or right arrow keys, that's H so looking down here, let's try to make sense of this. So the first component is V, which is the up or the down arrow, and it's multiplying that times the camera forward direction. And then it's adding that to H, which is the left or the right arrows, times the camera right direction. And so, if you think about it in the game, when we play the game and I pressed the up arrow key, what happens? The character moves directly away from the camera because it's multiplying this up arrow times, the camera forward direction. And when I press the down Arrow, it comes back the other way. When I pressed the left arrow, it goes off to the left, according to the camera. That's what's happening here. When I press both keys together, she seems to run, so it's like she's running diagonally. That's not what I want. So I suspect what we need to do is this is the problem where we're adding these two things together. We're going. We're getting a value that's higher than one. And so when you want to re calculate a value so that it is one that's called normalizing and so to solve this problem, what I did was I went over to the scripting reference in the scripting reference. I looked up the word normalize, and then I noticed that Vector three is one of the choices here. So I clicked on that, and then I see appear in the signature that this is a method that's part of the Vector three class, and it takes a Vector three value as an argument, and it returns a vector three. It makes a vector, have a magnitude of one when normalized, a vector keeps the same direction, but its length is one That's exactly what we need. So go back into my code and right here I want these two components added together to be the argument to this method. We're gonna surround them by parentheses, and then I'm going to say Vector three dot normalize. So I suspect this will solve the problem. We'll go ahead and save that and then go back into unity and play test the game. Now when I play the game, I can walk in any direction. I hold down to Arrow Key simultaneously. She's just walking. She's no longer running so that it was the solution to the problem. I can hold down either shift key, left or right, and she'll run. 26. Set up Cinemachine FreeLook camera: In this video, I'm going to discuss the Sina Machine Free Look camera rig, which is an ideal system for use with 1/3 person character. To get started, go up to the Cinema Sheen menu and choose create free look camera that creates a new item here in the hierarchy. So it just came into the center of the scene. I'm going to reset its transform to set it to the origin point in that place. Is it right at the feet of the character? The next thing I want to do is set up to follow and look at targets, so we want this freely camera rig to follow the character. That's what we can do is drag the character in the coal and drop it right here in the follow target area. Next, we need to have a look at Target that's separate from Nicole. We don't really have an object for that yet, So what we should do is create a new empty object. I'll say, create empty in the hierarchy, and then I'll rename that look at Target, and then I'll reset the transform of this empty object to the origin point and then move it up in the Y direction so that it's about at the characters I height, which is about 1.5 meters in this case. Now I need to go back to the cinema Sheen free look camera and then dragged the look at Target and drop it right here in the lookout slot. Okay, so now let's see what we have in the scene. We have the rig, which is shown here, and there's a lot of complexity built into this automatically. So we have a top rig, which is this upper circle, a middle rig and a lower rig on the bottom. And they're connected by this curve here. And so let's see what happens when we play the game. Right now, I'm not actually looking through the camera, so I'll click solo over here in the Inspector so that I'm actually looking through this camera rather than the virtual camera. And then I'll click over here in the game window and then just move the cursor up and down . And what's happening is the camera is moving along that curve that connects those rigs. And if I move the cursor to the left or to the right I'm orbiting around those rigs. And so in this way we have a really complicated and yet fluid system that we can use to blend between all of these different potential camera positions. And now, if I walk by holding down the up arrow key, you can see that well, I'm getting a little lost in space here. But what's happening is character is pulling the whole rig along, and right now it's easy to get lost. We have some fine tuning to do to fix this up and make it more robust, and in the next video, I'll show you how we confined tune the free Look camera rig. 27. Fine-tune free look rigs: So in this video, I'm going to find Tune the free Look camera rig. And as it stands right now, if I move around by holding down the up arrow key and I start moving the cursor around, I get really disoriented. And the reason for that is because we have this set up to use the look at Target as a separate game object. But as we move around, as we move the character around that look out, look at target stays put. So what I need to do is drag the lookout target into the Nicole object and also bring the Sina machine free look camera rig in there. A swell. We'll just drop it on Nicole like that. So now these become indented, so they become Children. Objects of Nicole. So now when I play, I'll go ahead and solo this camera click in the game window, and as I walk around by holding the up arrow down, I'm not getting disoriented anymore. Now let's start to find Tune the way that this works. If I move the mouse to the left, the character walks to the right, so I find that counterintuitive. So I'd like to change that behavior, and usually when you're in play mode, any changes that you make are lost when you exit play mode. But this is an exception because this has a save during play flag to make sure that selected. And then any changes that you make to the rig will be maintained even after you exit play mode, so that what I want to do first is locate the X axis and then uncheck invert, and then I'll click in the game window. And now, if I move the cursor to the left, the character walks left, and if I move the cursor to the right, the character walks to the right. So I find that to be much more intuitive. And so now I'm gonna stop walking and let's see if we can find Tune this rig. It's kind of awkward. It's kind of far away from her right now, so I'm going to scroll down. And in this area where we have orbits, we can control the shape of the rig. And for that it's also helpful to look at this in the scene. So I'm going to select the sin the machine object here and double click on it to frame in on that in the scene. Maybe I'll just navigate a little bit here to get a better look at what we're dealing with here. So first thing is, when I'm in the upper rig, I'm so high above the character. I'm gonna bring that down. I'm gonna move the height of the top rig down. Let's say 2 3.5 Will this change the number 3.5 meters and then I want the middle rig to be a little lower. Let's say 1.75 in the bottom rig. I want that to be higher at 1.5. So there's less of a height difference now between the middle and the bottom rigs. You can see that if I select this object here, you can see that relationship represented here, and you can also see it in the game. When I move around, I now have lost the solo condition. What? I'm gonna do it as actually elevate the priority to 20 so I don't have to keep clicking solo. And then I'll always be looking through this rig. Kevin a walk over here and get a better look at the character, and I'm also going to navigate and zoom in on the rig, just navigate in the scene to get a better look at what I'm doing here. Okay, so now we need to make this correlation between the rigs that we see in the scene and the view in the game window looking through that camera there. So when I move the mouse down, we go into the lower rig and we get an up close view, and that's good, giving us a kind of a psychological portrait of our character. And maybe what I could do is adjust some more of those parameters here, the radius value. I'd like to get a little closer to the character, so I'm gonna change the radius value to one meter just to get a little closer. And I'm gonna make the Middle Rigs radius a little tighter as well. A 2.5. And let's let's see what happens now when I come in closer now, that's interesting. I can see the character's face a lot more clearly when I move out to the middle rig just by moving the cursor drop, we're getting more of a shot of our whole body. And when I move up to the top, we're getting kind of ah, top view, More or less. I think the top view could be a little tighter gun to make this se 0.75 Okay, so now it's more of, ah view just of the top of her head Now in the middle rig the problem in the middle Regus that I'm just like I'm always focused on her head. So wherever I am, I'm always looking at her head because that's the look at target. But I'd like to kind of compensate for that here in the middle rig so that I see her whole body. We can do that by scrolling down. We have sections for top brig, middle rig and bottom rigs. I'm interested in the middle rig, and what I want to do here is change the tract object offset. So I'm gonna change that to a negative value. So it moves the camera down and I'll say it's minus 0.8 meters. I don't see what effect that has. So now I have the bottom rig. When I move the mouse up looking at the middle rig so I see her whole body and this is great for when we're actually walking around in the space, we can look at the character in the whole body. When we move the mouse down, we get more of, ah view of the character's head. When we go up, we get more of a top for you. But the problem here is that the there's kind of ah, but we're transition zone right in here because we put in that offset. We don't have an offset on top break. So I think even that out, going to go down to the top rig and change the offset here, too. That's a minus 0.6. So it's closer to the offset that we put in to the middle rigs. And now let's see, that's more fluid. So we go out and then we move up so it is kind of fine tuning that's always necessary when you're configuring a free let camera rig. But it's well worth time spent in getting it just right so that you can wander around and always have a good view of your character, what it's like to look at the world through their eyes, but also to be a bit detached so that you can see their whole body as they interact with things in the game environment. 28. Replacing animations in controller: in this video, I'd like to continue to find Tune the character, and we're going to examine the way that the characters animated. But 1st 1 thing I want to correct is when I exited play mode and went back in, I discovered that I'm not looking through the free look camera. When I play the game, the character moves around and you can see in the scene that thesis in a machine free look Camera is following the character, but in the game, I'm actually looking through one of the virtual camera Still. So evidently, when I did that, I learned that the priority value isn't one of the things that saved during play. So this is something that you have to change when you're outside of game mode. I'm gonna elevate the priority of the free Let camera to 20 and that should be higher than the priorities of the other cameras. Let's just go check a look at Sin Machine Virtual Camera one, and it has a priority of 11 v cam to as a priority of 12. And so, with the priority of 20 that will take precedence. And that means that we'll be looking through this camera when the game begins. Of course, you can change these priority values at runtime using a script that's not something that I'm going to cover. Instead, let's focus on the way that the character looks and the way that the rig functions. So let's go ahead and play the game, and now I'm looking through the Sina machine rig. That's evident because as I move the cursor, I'm moving around. And now if you look at the scene, it's a little tight. I have to say, I'd like to see more of the world and not just focus so tightly on the character, and I can do that by making a change to the field of view of the camera. I'm gonna change that right here from 40 to 60 degrees, and so now we're suddenly seeing a lot more of the space, and the rig still functions in an acceptable way. One thing we might do is bring it in a little tighter on the lower rig to compensate for this wider angle, gonna scroll down here and change the bottom rigs radius value to be even a little less. I'll say it's 0.75 so Now when I go in the game window, we get a little closer to the character. Okay, so I think I'm happy with the way that the rig works Now. I would like to take a close look at the character when she's standing there. She's in the idle animation, and one thing I don't like about it is the way that her fingers look. Strangely enough, they seem to be kind of unnaturally extended. And then when I walk, they kind of stay that way and maybe even get worse with her fingers. Kind of extended a little beyond, and I think that's a little odd. So what I'd like to do is use a different animation clip for the Idol and the walk animations, and I'd actually like to avail myself of some of the assets that come with Cinema Sheen. So I'm actually gonna get out of play mode, go over to the Senate machine menu and select import example asset package, and this is something that's well worth exploring on your own. I'm going to import everything, and this asset package comes with sample scenes that you can open and explore, and this will give you a feel for the different types of things you can do with cinema Sheen and the list is really extensive. We're just really scratching the surface here with the free look camera and the virtual camera. There are many different types of cameras he can use with Sina machine. So now I'd like to explore those example assets that we have up here. Go ahead and expand that open up shared models Unity Character, and then click on the animation folder there and in here you'll find a number of FB X files that have animation clips on them, and these were included because there's a character that comes in some of the standard scenes here in the center machine. Examples. So I'm gonna open up Idol. And in this fbx file, we have, ah, a number of different clips that we can choose from, and you can take a look at those. If you click on one of the clips and expand the preview window, you can play that and have a look at what that looks like here. It's hard to see it so small here in the preview, but what I'd like to do is swap that out with the asset that came prepackaged with our third person, uh, controller, that came from the standard assets. So to access that, I'll go to the animator window and open up the grounded blend tree by double clicking on the orange node. And then I'll click on the blend tree itself and then scroll down in the inspector and you'll find all of the different clips that are associated with this blend tree. You know, in particular, I'm most concerned right now with the Idol clip, so I'm going to expand the inspector temporarily so I can read these names. And there's the humanoid Idol quipping. If I click on that, you'll see where it's located in this fbx file humanoid idol, and it's inside the Standard Assets folder, and there's nothing saying that you can't swap these out for other clips that you find elsewhere. So I'm gonna navigate here to the animation folder inside the Sin Machine examples, and I'm gonna drag idol clip D and drop it here and substitute that for humanoid idol. And while I'm at it, I'm also going to take advantage of this walk animation and use that instead of the humanoid walk. And now let's take a look at how that looks in the game. I'll play the game and then collapse the inspector back and make it more narrow again. And now let's have a look at her fingers. They're different now because it's sourcing a different animation clip. I think it's more of a natural position with the fingers kind of rolled in a bit, not sticking out. And then when I walk by pressing the up arrow, I don't see that problem with the index finger in the middle fingers kind of sticking out beyond where they really naturally would go. I just find this a little bit more realistic, so now you know how you can swap out animation clips in your animation controller. 29. Integrating a death animation into controller: Now I'd like to integrate an animation that I downloaded in an earlier chapter that allows this character to die. So we had a death animation from Mix Imo that I now want to integrate into our character. To do so, we need to start by finding that asset, and it's right here. Nicole at standing react Death forward. It's an f B X file, so I need to drag and drop that into my Models Characters folder. And then once that comes in, you can see the asset which is right here. This is the animation clip itself, and if you preview that, you'll see that it doesn't work yet. We have to configure this asset first. So close the preview and select the asset itself at the top level goodly rig page and change the animation type from generic to humanoid. And we don't really need to create a new avatar from this model because we should copy it from the other Avatar. In particular, we want to copy the avatar from Nicole, so open Nicole and drag her avatar into the source slot and click apply. So now this animation clip will apply to the Nicole Avatar in particular. The next thing we need to do is get this animation clip into our finite state machine so I can drag it right in here and drop it. So this animation clip is kind of a standalone situation. It's not going to be part of the existing blend trees because presumably the character can die at any time. And that's where this any state node comes in handy. I'll just zoom in here. So there's any state I'd like to be able to trigger the death at any time. So I'll right click on any state and say Make transition and then connect the transition to the animation and then select the transition itself and then scroll down over here in the Inspector and you can trigger that animation clip with a condition. A condition is another word for parameter. So up here on the parameters tab, we have a number of different parameters that came with the standard controller, and we don't want to alter any of that functionality, but instead we want to add on to it. So I'm going to add a new parameter, and you can add parameters in any of these four data types. In this case, the ideal parameter would be a trigger. A trigger is like a boolean. A bull can either be true or false. The trigger can also either be true or false. But it can only be true for a moment, and thus it's a trigger that happens once. So choose Trigger and I'll give it the name deaf. And then to trigger that in the actual game will need to use a script that will call that parameter. And I've already done that for you, and I've supplied that. It's one of the exercise files, and I'll show you how we can integrate this script in the next video. But now let's test this out and see if we can make it happen just by clicking this round radio button here in the U I for the animator. So I'll click play and I'll play the game. And now I'd like her to die. So I'll click on the death radio button here. But nothing happens yet because I haven't connected this. All I've done so far is create the parameter right. So I need to do is get out of the game, select the transition scroll down in the inspector and add the condition for this transition to occur by clicking plus down here. And then there's, Ah, drop down menu and you need to scroll down and select death. And it doesn't have any additional parameters with it because it's a trigger just happens once. Okay, so now this should actually work. I'll play the game and then click the death radio button. And sure enough, she dies. However, she's floating above the ground, and that has to do with her route transform. So let's get out of the play mode. And then to change that, we need to access the Death Fbx file and we need to goto animation. And I'd like to change the compression toe off so I can show you what the compression is all about. First, and I will scroll down and click apply. So in this case, I'm gonna open up the animation window, which is under window animation animation. Not to be confused with the animator, which we've been working in. So here's the animation window. I need to select this animation to see that here, so I'll click on standing reactor Death forward, and now you can see what's actually stored in that asset, so there's a huge number of key frames in here. Each one of these little diamonds is a key frame, and there's key frames at every frame for every object in the Avatar. So it's very, very complicated. We can save a lot of memory if we reduce the number of key frames, and we can do that by selecting this asset, and I'll just move this over a little bit. And then what I'm going to do is choose animation compression, two key frame reduction, and then I'll scroll down and click apply. And now there are far fewer key frames that are stored. It only uses the key frames where there are changes. Another thing we can do in here is bake the root transformation position into the clip, and I think that's the problem that we're having, where, when she dies, she's kind of floating in space. That's what we need to do is big. The route transformed position in why, which is the vertical direction above the ground into the post. So check here and then click, apply, and then I can go ahead and see if that works we'll close the animation window, play the game, Actually, before I play the Gana uncheck this radio button so she doesn't immediately die. And then I'll play the game and there she is so she can walk around. Everything's good, and then when she dies, I'll click the death animation and you can see that that happens and she falls right on the ground, which is what we expect. So now we can trigger her death here in the parameters window. In the next video, I'll show you how we can get that to occur when she follows off of an object using a script . 30. Scripting death by falling: at this stage of the game, we can cause the player to die by manually clicking the death radio button here in the animator window, and that demonstrates the functionality. But it's not accessible from the game itself. So what we need to do is have a script that will cause this to be triggered under some type of condition in the game. And I've supplied you with the script that does exactly that. So I'm gonna get out of the game and then go into the file system and you'll find this script right here in the Exercise files folder Trigger Death by falling. I need to bring that into my project so I'll go to the Assets folder. I'm just gonna tidy up here and close some of the sub folders, and we have used some scripts in the past, but they were part of the standard assets. This is a custom script, so I'm going to make a new folder for it called Scripts. And then I'll double click on that folder to go into that here in the right pane, and then I'll go back into the file system and Dragon dropped the trigger Death by falling script in here. And let's take a look at that here. I'm going to double click on that to open it in my default code editor, and you can read through the code if you're familiar with C sharp. But let me just quickly summarize that I have one serialized feel that makes it accessible in the Inspector, and that's called the Falling distance threshold. And I have that set toe one meter by default. So she has to fall at least a meter in order to die. But that distance is configurable, and it also relies upon a specific trigger name called Death with a Capital D. So it has to exactly match this word, and I believe that is what I called it in the game. So if you called your trigger something slightly different, maybe it was all lower case. Then you're gonna have to change that either in the parameter or here in the code. We don't need to make any changes to the code, but you could just read through it to see how it works if you like. And you can also use this as a jumping off point for your own games. so I'll go back into unity and to take advantage of this script. What we need to do is get it on the character. So I select Nicole in the hierarchy and then I'll scroll down here to the bottom. And Dragon dropped this script at the bottom of the list where it turns blue and there's trigger death by falling. No, As I said, there's one parameter that's accessible here in the Inspector. The falling distance threshold. Let's just see how that works out of the box. I'll go ahead and play the game, and then I walk over here to this ramp. Incidentally, if you have the animator open, you can see that we're currently in the grounded state. This Progress bar is showing us that were in that blend tree. So what I'm gonna do is walk up the ramp just a short distance, and then I'm gonna hold down the shift key and just run off the edge. And when I do that, she dies. You can see now in the state machine that she's dead. This is no longer running. So that got triggered by the script because she fell more than a meter. But that's really not very far, and I think that she'd be more robust than that. She wouldn't just die such a low height. So what I can do is change that here in the inspector. I'm going to say that she has to fall at least four meters arm or in order to die. So I changed this parameter to four, and now we play the game. Let's test this out and see if it works. So if I walk over here and go up the ramp again, part way and to save time, I'm going to run up the ramp by holding down one of the shift keys. So now go over here, and if I jump off of here in the middle of this area, I fall on this platform down below and I didn't die. Evidently, that's less than four meters, so that's good. I think she should be able to jump on that platform. But what if she falls from the full height of the platform? Let's see what happens next. I'll go up here. I'm just gonna run right off the edge and see what happens. Sure enough, she dies because it's more than four meters, so this is a way that you can trigger this parameter through the use of a script 31. Walking up stairs using colliders from hidden ramps: if you've tried to get the character toe walk up the stairs, you've probably met with frustration up to this point. So when I walk over here to the stairs, watch what happens. I just run up against them and I don't get anywhere. You may have thought, Well, maybe I can get up there by jumping. So if you hold down the space bar, you'll jump. And that's one way to get up the stairs at least one step at a time, and the character jumps way too high. It's like they're a superhero If you try to run up the stairs, you might have gotten up the stairs in fits and starts, and it's very awkward. So this is typically the problem with Stairs is that the capsule collider on the character has a lot of trouble getting up this disjointed type of geometry. So what we can do to get around that is to include ah, hidden object, which turns the staircase into more like a ramp, and I've actually provided an asset for that purpose. Exercise Files folder. You'll find a hidden ramps fbx file, and I'm going to drag and drop that into the architecture sub folder under models, and then we'll click on that asset here. I don't need to convert units because I modeled it in meters using sketch up pro. I'll scroll down here and enable generate colliders because I need those colliders in order to walk up the ramp with the character, and that's it. I don't need to generate light map you these because ultimately these ramps are going to be hidden. I'll click, apply, and then Dragon dropped the hidden ramps asset into the hierarchy. And there's actually two ramps here, and I showed them in red just to get your attention. There's a ramp over here on this staircase on that platform in the distance, and there's a big ramp here on this major staircase. So what we can do is expand that, and you can see the different parts within. And if I just turn this off, it's not going to work because we've also turned off the colliders. So the solution is to be more specific. I need to leave it on and then to go into the mesh and in the mesh. They're different components. There's the transform, the mash itself, which contains the geometry the mesh renderers, and this is responsible for displaying the mesh and the Mess collider, which was generated and that has the shape of the mesh itself. So what we need to do, as you may have guessed, is disabled. The mash render. So now we get the best of both. Worlds were able to use the collider that's based on the mesh, but we're not able to see the object. So I want to make sure I do that also to mess, too. Turn off its mesh renderers. So now I'll play the game and then we'll see if we can get up the ramp. I say ramp because it really the character is going to encounter that now as a ramp rather than a staircase. But it looks like a staircase in the game, however, she walks up the staircase painfully slowly, and this is really due to geometry, of going up a steep slope. So what we can do is adjust the way that the character behaves a little bit to make her go up at a more reasonable speed. So let's select character and scroll down to access her third person character script, which contains these different values that control the speeds of things. So one thing I notice is her jump was way too high. So I'm gonna decrease the power of the jump toe. Let's say three so she doesn't jump very high. And then I can also decrease the gravity multiplier down to one is, I think, by default it's up to, so I'll decrease that. And also we can increase the speed at which she walks. So I'm going to increase the move speed multiplier to one point three. And we should match that with the animation speed. Or it would look like she's moving faster than she's walking. So you should always make these two parameters match unless you're having some kind of mismatch between the animation and the speed of the route motion of the character. So I'm going to make these both say 1.3 and then I'll go ahead and play and, well, test it out. So now she walks a little bit faster. She goes up the stairs at a more reasonable clip, so it's kind of the best of both worlds. We're now able to navigate staircases at a reasonable speed, although the character is actually encountering that staircase more like a ramp. So now you know the secret about stairs. Make them into a hidden ramp and you'll be good to go. 32. Bringing in a new character: in this video, I'd like to bring in another character in particular I'd like to bring in May. Who is the character that I exported from auto desk character generator. So at this stage, we just have the Nicole character and we have many different assets and the characters folder related to her. So to stay organized, I'm going to create a sub folder with the name of this character Nicole. And then I'm going to select all of the assets in here and dragged them into this Nicole sub folder. And then I'll go to the Characters Folder and create another sub folder called May. And then I'll go to the May folder and switch over to the file system and bring in the May unity rigged dot fbx file. Dragon dropped that in here. Select the asset. Everything's fine on the model page. I'll go to the Rig page and change the animation type two humanoid create from this model for the Avatar and click apply. I'll go to the animation page, and there's no animation here that I want to import, so I'm going to uncheck that and apply, and then I'll go to materials and extract the materials first, and they should go into the May sub folder and then extract the textures in the same folder . So this has a different structure, as compared to the character that was exported from fuse. Since a little simpler. There's only one material and just three texture maps. Take a look at these. We have a color, we have a normal and we have a speculator. There's actually nothing that we need to do in photo shop. One thing I should do here is tagged the normal map as such, so select that. Change the texture, type to normal map and then click Apply. And then I'll go to the material and drag the color map into the albedo channel, and I'll drag the normal map into the normal channel. And I have a metallic slot here, which isn't useful because I have a speculum app. So I need to change the Shader to the standard speculator set up, and then I can drag and drop the speculum app into the speculator channel like that. The rendering mode should be opaque, so I think the materials all set up. Then I'll take the character and dragon drop her into the hierarchy, and I'm just going to navigate in the scene and have a look over here and she's coming in at the origin point, so she's overlapping with our previous character. That's what we need to do is move one of them over because I'm configuring May I'll choose to move Nicole over out of the way. Some arbitrary distance. So May has already set up with the material. She's already looking good right out of the box. So in the next video, we'll start to configure the different components on the May object so that she can function as 1/3 person character. 33. Designing a third person player gameobject: Now that we have theme a character's skin in the scene, it's time to start adding functionality to her. And let's examine the coal just to review all of the different components that are necessary to create 1/3 person character. So we have a transform component. Like all game objects, Nicole has an animator that references the third person animator controller that we've customized, and it also uses Nicole's Avatar, which is in the prefab. It has a rigid body for physics, a capsule collider, four collisions, 1/3 person character to control the speed of movement, 1/3 person user control, which interfaces with the input system and the custom trigger death by falling script. So we could at each one of these components to May. But every time we bring in a character running, going to have to go through that long process. So I suggest creating 1/3 person player that has all these scripts on it, and then it will be very easy to swap out different skins and avatars. So let's do that by creating an empty game object, and I'll just rename that and call it third person player, and then I might want to tag this as a player so that in the future, if we ever want to get a hold of this object through code, it will be that much easier because we can refer to its tag. So right now, this is just an empty object has a transform and the transformers at some arbitrary location. So I should reset the transform to the origin point. Next up, let's look in the cold and see what she has next. An animator. So we need to get an animator on our third person player, so at a component, and I'll type in animator here in the search. And then I could just add that. And then we need to reference the third person controller, and I can click on this circular button here and I can select it from the list and then we need an avatar. This is the one area that we have to make this specific to the character in question. So I need to reference Maze Avatar and that's located in her fbx file at the bottom. So I'm gonna drag and drop that in here. I'll go back to Nicole and see what's next on the list. So if you recall, um, these components were all dependencies on the third person user control script, so I should be able to locate that in the assets. And it's under standard assets characters, third person character scripts. And then there's the third person user control. So I'm going to go back to my third person player that I'm building on a dragon dropped the third person user control in here. When I do that, it's going to not only add that, but the rigid body, the capsule and the third person character. However, all of these come in with their default values. So to save time, I could go to Nicole and let's say we want to copy all the values that are in her third person character script into the matching script on the new character. So what I'll do here is clicked the gear icon and say, copy component, And then I'll go over to the new third person player and go over to this matching component . Open the gear icon and say paste component values. And that just enters all those values automatically. So there's no need to make notes. You can just copy and paste the values. Okay, I'll go back to Nicole and let's see what else we can copy and paste in here. How about the Capsule Collider values that might be helpful? I'll go ahead and copy that and then go over to the third person player and paste the component values in and let's see what else we need. We have a rigid body. Doesn't really need to have any changes to it. The third person user Control, doesn't have any parameters that we need to change. And all that were missing now is our custom script. So I need to locate that in the top level Scripts folder, and I'll just drag and drop this in here on the bottom, and I'm gonna change the falling distance threshold to four meters. I remember that parameter. It's now. I think we have all of the components to make this work as a third person player. However, we're missing the skin, so what we need to do is take may appear, and May has an animator component on her by default, and we don't want that. So what I need to do next is right. Click in the hierarchy on may and choose, unpack, prefab and then remove this animator component. So it just has a transform. And then all Dragon drop may into the third person player and make me a child of that new player object. So the third person player has all the different components that we need and then may just has a transform because May is really just the skin. So let's go ahead and test drive her. Before I do that, I'm gonna turn off Nicole. So we're not driving two characters and I'll go ahead and play and I can walk around with May, and there's a few other refinements that we need to make. For example, I see lights on that we need to attend to, and we'll also have to hook up the free look camera rig to this character as well. And I'll do that in the next video 34. Connecting FreeLook camera to third person player: at this stage of the game, the character could move around, but we're just viewing her from the virtual camera, not the free look camera. And I noticed there's a bunch of different shadows on the ground that are being cast by some light sources that are moving with the character. So let's fix that. I'll get out of play mode, open up the third person player and open up May unity rigged. In here, you'll find a lights node, which contains a number of spotlights that you can see here in the scene. I'm going to toggle the lights node off by un checking its set active flag, and that really fixes the light problem. We just have one shadow now, and that's being cast in the same direction as all the other shadows in the scene because it's coming from the directional light appear. So I've solved the lighting problem. Next up on the agenda is thief relook camera. So that's in the Nicole object. I'm not open that up. It's select Nicole and set her active, and right now, the free look camera is in here inside of the Nicole object, so I need to pull it out of there. But before I do that, I want it to be in the same location as may not offset this arbitrary distance. So I'm going to reset the transform of Nicole so that she is at the origin point and then everything will line up properly. Now I'm going to drag the free look camera out of Nicole and drop her right on the third person player for clarity. I'm gonna close. May unity rigged. You can see that now. The free look is at the same level as this character. We also need to look at Target, just part of the way the free look camera works. So I'm gonna drag that out and drop it on the third person player, and then I'll go to the free look camera and it's still referencing Nicole as the follow target. And that's not correct now. So to drag the third person player node and drop it here as the follow and the look at target is still correct, it should be located at the character's head height, which is correct. Okay, now I'm going to selecting Nicole and turn her off, and I believe that the camera should function properly. Let's go ahead and test drive it by playing the game. And as I move the cursor, you can see that we have the free look camera functionality. Just by moving the cursor around, I can move all around now hold down the arrow keys, and as I walk, the camera moves with May because it's a child now of the third person player, and so is Mayes skin. So as we move the player around, all of that complexity moves with it. So now I'm going to get out of play mode, and in the next video, I'll show you how we can swap Nicole back into this player, and it will give you an idea of how easy it is to swap out different skins once you have set up this third person player structure. 35. Swapping out characters within the third person player: No, I'd like to complete the circle and swap out May for Nicole within the third person player . So I'm going to drag than the coal node into the third person player and set her active by checking the box next to her name in the Inspector. So right now we have two characters occupying the same volume of space, so I'm going to select the May skin and toggle that off. And then I'll go back to the coal and recall that Nicole has all of the different components on her still, so that would be a duplication of what we have on the third person player note above. See, this has all of the functionality that we need to drive the character so we don't need it again on Nicole. So the solution here is to actually remove all of these components by clicking each components gear icon and saying, Remove component, and we have to do this in a certain order. We can't directly remove the animator because the third person character script depends on it, and the third person character script depends on the third person user control. So the first thing we actually need to remove is the third person user control, and then I can remove each one of the other components. So I'm stripping this down all the way to just having a transform. And you can't remove the transform, of course, because all game objects have to have a transform to be located in three D space. So that's Nicole. She's just the skin now, and let's see if she actually functions before I test drive the game. Mel, let's go up to 1/3 person player and just look that the avatar is still connected to May. So this is the one change that we need to make in the component structure here. I need to locate the avatar for my current character in the file system, so I need to go into the project window. Open up, Nicole, find her avatar and Dragon dropped that in here. I should be able to play the game now, and control in the coal, have our move around. That works just fine. So now she's streamlined and easy to swap out. Let's say I want to go back to May. All I have to do is ta gold. Nicole off. Tuggle may on go to the third person player and bring in May's Avatar and put that in the Animator. And now I can drive May instead. So, as you can appreciate, it was worth the trouble of creating the separate third person player node because it makes swapping characters very easy. 36. Using legacy characters: ID like to show you how to import legacy characters that were developed before the mechanism animation system was integrated into unity. And you know that as theano Mater Window here. So I'd like to source a legacy character from the assets store. So open up that window and I'd like to search for an asset that was developed by Unity Technologies called Kyle the Robot. So just type in Kyle and it comes up right away here. Space Robot Kyle. I'll go ahead and click on that and then download that and imported, and it has a material and fbx file and a couple of texture maps. Now what's interesting about this is the texture. Maps are not bundled into the fbx file. Instead, they're separate, and that's part of the legacy system. So now we have Robot Kyle over here at the root of the Assets folder and just for clarity. I'm gonna drag that into the Characters folder here so that it's at the same level as May and Nicole and then I'll go back to the scene and let's examine what we have imported here . We have a model sub folder with the FBX file here and I'm not sure what scale it is at. So let's just go ahead and drag that directly into the hierarchy, and he actually comes in at the proper scale. As you can appreciate here he's in a pose rather than t pose. So his body makes more like the Letter A. And let's examine his asset here and see on the rig page that he comes in as animation type legacy. And so what I'd like to do is change that and upgrade him to be a humanoid. And we're going to create an avatar from this model and I'll just say, apply. And then we don't have any animation on this. I'm going to uncheck important animation and apply and the materials. Let's check that out. Here we have it says location, use external materials legacy. And that is the situation that seems to be working for us right out of the box because it has a separate materials folder and a separate textures folder. And evidently that's working because we see those materials on the robot directly, and you can examine the material that's here robot color, and it uses a legacy shader, which I can change now and upgrade that and have that be the speculator set up. And actually, in this case, it doesn't have a speculum app, So I think I'll just use the standard shader. So it has a metallic quality to it. And seeing that he is a metal robot, we might want to take advantage of that. So I'd like to get a closer look at Robot Kyle. And to do that, I'm going to toggle May off, and I'm just gonna navigate here in the scene and get a better look at him. And then I'm going to select his material and increase his metallic slider. So now when I boost that up, he looks more like he's stainless steel. And if I pull that down, it looks more like he's brushed aluminum. So I kind of like the stainless steel Look, I'm gonna crank that all the way up to one, and then you can adjust the smoothness value as well to control how the environment reflections are displayed on the character. So I think he looks pretty good. I'm just gonna tweak these sliders a little bit to my liking. And let's go ahead and examine his avatar next. So I'm going to open up Robot Kyle here in the model and take a look at his avatar Mina click configure avatar, save the current scene and have a look at him. So what happens is unity automatically a justice avatar into T pose, because it's necessary to sync up with the animation clips that are used in this system. But notice that this particular model doesn't have the right number of bones. You see, it's missing some bones in here. They were never part of the rig. I don't think that's much of a limitation here. Seeing that he is a robot, he probably can't bend in quite the same way as, Ah, a human can. And you can see that these air just missing here from the Avatar. So any animations that animate those notes are just going to be ignored. I'll just go ahead and it's a done, and now I'd like to integrate this robot and drive him as 1/3 person character. So I'm going to drag and drop him into the third person player and then looking at Robot Kyle. He's a prefab right now, and he has an avid animator component on him by default. So I don't want that. I'm going to right click on that and unpack the prefab and get rid of this component. So it's stripped debt down just to the transform, and then I'll go up to the third person player and I need to put in Kyle's avatar in here, and I think that's enough. Let's go ahead and play the game and see if we can drive the robot around and it works great. So now you can appreciate all the steps that are necessary to repurpose a legacy asset for use with the animator system. That's part of the modern version of unity. 37. Using high quality commercial characters: in this video, I'd like to import a high quality, commercially produced character that I downloaded in an earlier chapter from Render people . If you recall, we downloaded some free rigged people and I'd like to extract that here. And this Zip archive actually contains a couple of other Zip files. So we have Alison and Eric. I'll expand Eric and see what we have in this package. So we have a lot of different assets to sort through here we have different FB X Files to choose from, and these are provided for a wide variety of different programs. So we need to choose Theus aet. That's ideal for unity. And evidently, these assets come in different forms. There's a Y up version and a Z up version. Unity, of course, uses a Y up coordinate system, so we need to use one of these two assets here. This is appended with E the Suffolk STI or A and that refers to t pose or a pose. Ideally, we'll use t pose, so this is the asset in question. So now I'm going to go over to my Characters folder and create a new sub folder called Eric and then I'll double click on that over here on the right pain to go into that folder, go over to the file and dragged this asset in there. And then I'm going to select that asset on the top level, and I'm just going to drag and drop him right into the hierarchy, and he comes in at the right size. I'll go in and struggle off Robot Kyle for now, and I'll select Eric here and you can see that he has an animator on him that we're going to have to remove. But first, let's deal with his materials. So I'm going to go to the asset here. And first of all, go to the rig and make it humanoid and then go to materials and extract any materials that are defined in here. That copies that material in here as a separate asset and also extract the texture maps that are part of the fbx file. And let's see that brings in a single diffuse texture map. So here's the material. I'm going to drag the diffuse texture map in there, and that seems to work pretty well. But let's look back at the file system and If you notice there's a text sub folder that's easy to overlook, especially in this folder that has a lot of other assets. I'll go in there and you can see that there are additional texture maps that aren't part of the Fbx file at all. But they are supplied here so we can take advantage of this. It looks like we have some different options. We have a normal map, which will be useful. We have a gloss map, which will also be useful. So it's like that we have a diffuse gloss and this is not the right combination for unity because he remember, diffuse is combined with a pass ity and speculators combined, combined with gloss in the standard Shader. So this is not a good combo for us, so we're gonna have to build that up ourselves. Thankfully, they provided separate files for a diffuse and gloss. So I'm gonna bring these files into my character folder and now we have a normal map that I should tag as a normal map and say apply and then we have Well, we have a copy of the diffuse map here. I didn't really need to bring that in again, so I'll delete this one. Now we have a gloss that we have to deal with in photo shop. So I'm going to double click on that to open that in my default image editor. And so gloss should really be the Alfa Channel speculator. Should be the RGB. So this is all wrong. So I need to convert this from RGB into an Alfa Channel. So I'm going to select all and then copy this to the clipboard, making Alfa Channel paste from the clipboard into the Alfa Channel, go back to the RGB channels and choose Edit Phil and fill with black. So now that information is in the Alfa Channel and the RGB is just black. I'll see this as a file that has the names, speculator and gloss in that in a format that supports an Alfa Channel off the save it in the photo shop format. And then I'll go back into unity and that should show up here. There it is, select the material and then dragged the speculator gloss material in here. But I need to have ah, shooter that supports that. So I don't want to use the metallic shader I'm gonna use the standard speculator set up, and then I can drag this in here and now I can control how much gloss there is with this slider, because gloss is another word for smoothness, and I also need to bring in the normal map. And that makes a big difference in terms of the wrinkles that we see on his shirt. So now, to make him functional, I need to select this object in the hierarchy, and I need to now break the connection that it has with the pre fabs will unpack the prefab , and then I can remove the animator component, stripping it down just so there's a transform. We'll just rename this now and call it Eric for clarity. And I'll bring Eric into the third person player, making it a child object of the player. And then I'll select the player itself and bring Eriks Avatar and bring it in here to the animator component on the player. Now, play the game and let's see if it works. It appears to work really well. Now. In the next chapter, I'll show you how we can make the characters look even better by using post processing and Sina machine extensions. 38. Making character prefabs and overrides: up to this point. We've been breaking connections with pre fabs as we proceeded to create our various characters. But at a certain point in your process, you'll want to re create your own pre fabs because pre fabs are the way that you get assets to work in multiple scenes or levels of your game. Right now, the third person players exist here in the hierarchy within this scene main. But I can't get them into another scene unless I have them exist. Is assets on disk? In other words, they have to show up down here in the project window in order to drag them into another scene. So I'm going to expand this third person player, and I'd like to kind of make this generic before I turn it into a prefab. So what I'm going to do is select all of the characters that air in here and drag them out and drop them just up here where we see a blue line that puts him at the top level. And then I'll select the third person player and clear out its avatar. This is referencing Eric right now, so I'm gonna click this target icon drag to the top and choose none, and that makes it generic. I want to keep the third person animator controller in here because that's the same controller that I want to use on all of my characters for my third person characters. So I think it's just about as generic as I want it to be. One thing in here is I could check out the Sina machine free Look camera, and it looks fine because it's just referencing the third person player and the look at Target, both of which I have here. So now I'd like to turn this third person player into a prefab to stay organized. I'm going to go to the root of my Assets folder and create a folder in there called Pre Fabs. And then I'll go into that folder and to create a prefab, all you have to do is drag your third person player into the pre fabs folder or any folder , and it will automatically convert that into an asset that exists on disk. It has the file extension dot prefab, and we can edit that by selecting the asset and saying open prefab. It opens it up here in a different window. It almost like it's a scene, but it's not. It's really just a NASA set, and we can open that up and access the parts of it that they could go back by clicking this arrow to go back up to the main scene. Incidentally, you can also access that by clicking the arrow here on the right of the prefab. It takes you right in there without having to select the asset first, and then I can go back. Another way is you can click on this and click open right here. It takes you in there. It's another way to get in, and this is how we get out. So now the third person player is a prefab, which we can reuse in another scene. That's great. However, it doesn't have any characters in it. So I don't want toe bring Eric in because then Eric would exist in every scene, and maybe I want to use Nicole in a different scene, not Eric. So what I should do is make each one of my skin's that I have set up as a separate prefab. That way I can reuse them in any scenes in the future. So I'll take Eric and just drag and drop him into the pre fabs folder, and that makes him into a prefab. It's just that easy. His icon turns blue, and then I want to do the same thing for each of the characters. So I'm gonna turn them on and then dragged them in here and make them pre fabs. So these air just the skins. And with May I'm going to actually rename her and get rid of this information. Just we have her first name, turn her on and then dragged her into the Free Fabs folder. So now each one of our characters exists as a prefab. That's great. I can reuse them in any scenes in the future, but right now it's a little cluttered, so I'm gonna select these and toggle them off. I'll leave Eric on for now, and I'd like Eric to work with the third person player, so I'm going to drag him in there and make it a child object. And now it has a plus symbol, their meaning. This isn't override on the third person player prefab, and you can see that also over here, where it says overrides. There's no overrides on Eric. But if I go to the third person player, Eric exists as an override on the third person player. We could remove him by saying, Revert, all but I don't want to do that. I want to use him there and let's see if you still works. I'll play the game And he doesn't work yet because I neglected to reference his avatar. You just stays in t pose. So what I need to do here is reference Eriks Avatar. And that avatar exists not in the prefab, but in the model. So I have to go back to the model, find that avatar in reference it here. And when I do that, it shows up in bold type, indicating that it's an override. So go ahead and play now, and I think it will work. And there he is. He works just like he did before. The free look camera rig is working properly, and the advantage that we have now is that I can reuse thes assets in different scenes in the future. 39. Using the Cinemachine collider extension: ID like to show you how to use a sina machine extension to make the camera movement more believable in terms of interacting with objects in the world. So right now we have the free look camera rig, which works pretty well. But when I walk over here to an enclosed area, say, underneath the ramp by this wall, I'd like to get a view of this before I test drive it in the game. So I'm gonna go up here to this scene and navigate so I can see that area as well. And then I'm going to select the free look camera here in the hierarchy so we can see it's gizmo. And now, when I move around in this area the camera, Just by moving the cursor, you'll see that the camera goes right through the wall. It's like it doesn't even know that the wall is there and that kind of blows theologian of solidity that this wall must have. If we're gonna actually believe that it's a wall, we shouldn't be able to go right through it like that. But there's nothing stopping us at this stage because the the free look camera is just following the rules set out in the rig for the bottom rig, middle rig and top break. But it doesn't know about the walls, so we can add that awareness to the camera. Using an extension, I'll get out of the game, and then I'd like to add that extension onto the free look camera. And right now that's part of a prefab. So if I did that at this point, it would exist as an override, which would only mean it would be in this one scene. So if I brought this into another scene, the override wouldn't be there. If you want to make it part of the asset itself, what you can do is open the prefab and then add that functionality here. Then it will work in all the scenes. So that's my preferred workflow. I'm going to select the Sina Machine free Look camera here and scroll all the way down to the bottom of the Inspector and add an extension from this drop down list. There are many extensions to choose from, and I want the Sina Machine Collider that's going to add a new script of that name below and has obstacle detection functionality built in, and it works pretty well out of the box, but I'll make maybe one change to it just to refine it. So let's go ahead and play. But before we play, we're note that we are actually in the prefab, so I need to return back up to the main scene, and then I can go ahead and select the free look camera and then play the game. And then I'm gonna walk over here to the same area by that wall. And when I get over here, watch what happens now both in the game and in the scene. When I bring the camera over here, the camera is actually following the edge of that wall. You see that and in the scene you can see some yellow yellow lines that exists there, and that is a result of this extension because it knows there's an obstacle there. It's altering the path that the camera takes to follow along the edge of that obstacle, and this makes for a much more realistic behavior. Another thing we can do is let's say I'm gonna walk under this enclosure over here and to do so, I need to Crouch. So you do that by pressing down the letter C to go into crouch mode. And this is built into the standard animation controller and script that comes with the standard assets. Some of the crowd gender there and release the Seiki, and it knows to keep me crouched because I'm under this geometry. So now if I go in there, the camera takes a different path, and I'd actually like to see that over here in the scene. So I'm just going to navigate so I can see what's happening in here. So this is actually below the bottom rig. But the script is figuring out that I need to be in this area here underneath, so it keeps the camera down in there, which is pretty good. But now I would like to adjust the way that this works a little bit, and I'm gonna stop the game, go into the third person player again, opened the prefab select the free let camera scrolled on the bottom where we have these parameters, and I'm going to increase the camera radius to a higher value. Let's say it's half a meter. Let's see how that effects the situation I'll go back up to the main scene, play the game again and walk over here to the same area. Maybe I'll run and then I'll crouch and go under there again. And now in the scene, you can notice now that the camera has a larger radius value. This is going to push the camera closer to the character, which might be more interesting in this confined space because we get a look at his face a little closer because of that. So this is a way that you can refine the way that the, uh, the motion happens in a confined space by altering the size of the camera. So these were some of the considerations that you can have here with controlling the Sina machine camera with this collider extension. 40. Setting up post-processing and anti-aliasing: Now I'm going to begin adding post processing effects, and this all starts with an asset, which is a post processing profile. I'll create that asset here in the root of the Assets folder, the post processing profile, which I'll just call P P p for short. And we need to add effects to this. So I'm going to add effect Jews, Unity and let's start with Vignette, open this up and click all to enable all of the different parameters. And just so that we can see this, I'm going to increase the intensity about halfway. I'm not really concerned with configuring any of this yet because I can't actually see it in the game or the scene as yet. The next step in this process is to select the main camera scroll all the way down and add a new component, which is the post process layers of type in post, and then add the post process layer. And there's a warning here because no layer has been set. We don't really have a layer by default to use, so I'm going to go over two layers here in the top right of the interface and say edit layers, and then that shows me the tags and layers item here in the inspector. I'll open up layers, and the first user configurable layer is user layer eight. I'm just gonna call that post. We'll type that in, and then I'll go back to the main camera, scroll down again and select the post layer from the list. And then you can use anti alias ing in the post processing system. And this is an alternative to using the anti alias sing, which is typically set up through the project settings. So if I go up to edit project settings under quality, here's where you would traditionally set up anti alias ing. I'm not going to use this system, though. I'm going to prefer to use the post process, anti alias ING system. So in order to do that, I need to go up to the camera and right here under M s a A, which is a kind of anti alias ing. I'm going to say off, and if you look in the game window, you can see that these diagonal lines look much more jagged now because I'm not using that anti alias ing. That's part of the quality settings. So instead I'm going to have to rely on the anti ale Issing, which is in here. I'm going to use the S m a a method. And now look at the diagonal lines are much smoother than they were previously. You can try out the different modes and pick the one that you like the best. I'm going to leave it in S m a A with high quality. And now I still need to get the post processing profile shown in the camera. And remember, we're looking through a Sina machine camera so that is used, you know, piped through the main camera through the sina machine brain component, which is already on there. So in order to get the post processing effects to show up, I need to go into my third person player, select the Sina machine camera scroll all the way down, and add an extension to that. This will act as an override here in the third person player prefab. I'm going to add the Sina machine post processing script and scroll down, and there it is. And so finally, to get this to work, we need to drag the post processing profile asset in here as the profile. And now we can finally see the vignette effect taking over in the game window and in the scene. In the next video, I'll show you how to create different post processing effects that improves the look of the entire scene. 41. Configuring post-processing effects: At this point, I'm able to see my first effect through the game window and also in the scene, namely, the vignette effect actually don't really want to use have been yet in this game. It's entirely optional, but I just used it kind of like a canary in a coal mine to show that the post processing effects were working. But now I'm going to go select the P P P asset here and disabled, and yet and then collapse it. I'm going to add some effects that I do want to use. Now we'll add ambient occlusion. First. I'll open that up and by default when you first add in effect, it's not enabled. You have to choose three different parameters that you want to enable and the more parameters that you enable, the more memory that it will take in the game. So here I'm just going to say all, and it says ambient only works with cameras rendering in deferred an HDR. I'm not going to do that, so I don't really need that parameter isle de Select it. I'd like to increase the intensity of ambient occlusion upto one, and as I do that you can start to see it darkened areas in the game and in the scene. The idea with ambient inclusion is areas that are sheltered, get more sheeting, and this is a way to simulate the shadows that appear with ambient lighting. And so now that I have set this up, I can easily tuggle it off and on to make a before and after comparison. So I think it adds something desirable to the overall look of the game. I'll continue on and add another effect here, auto exposure. And this is quite helpful if you have a character that's moving in it exterior environment into an interior or vice versa, because the lighting is very different in these areas. And in this game we have these sheltered areas under the ramps that are dark, and so it will be helpful to use auto exposure. I'll click all to turn all of these things on and actually don't need filtering. I'm gonna disable that, and then I'm going to drag the sliders format minimum all the way to the bottom and maximum all the way, the top and then exposure compensation I'm going to decrease down to about our own 0.25 or so, and so that has an effect. And it looks too dark in the scene over here. But we're gonna keep going in adding additional effects that will brighten that back up. So collapse this now collapse Ambien inclusion. Now I'm going to add bloom, which will add brightness to the bright, the areas that are already bright. I need to open that up and say all and actually I'm gonna say none and just turn on intensity it, make intensity, say one. I only need this one parameter. Now this is going to Brighton is going to add some kind of a glow, and you can just see it over here on the ramp. When I tuggle it off and on, you might be able to just perceive a little bit of kind of bright white glow or bloom coming off of the brightest surfaces. And when we're running around in the game, you'll see this effect even more. And now I'm going to add my last effect, which is going to be color grading, and I'll say all to turn everything on. And I'm gonna change the mode to low definition range, and I'm going to increase the color temperature to warm it up a little bit, gonna drag that up to around 30 which seems too much right now. But then I'm going to decrease the saturation down to about minus 30 or so and increase the contrast up to around 32. Let's see how it looks in the game. I'll play the game, and I'd like to focus on the game window. So I'm just gonna make that larger now. And the automatic auto exposure is happening as I move the free look camera around in areas where it's brighter or darker, the auto exposure is changing the exposure value dynamically. So if I walk over here into this dark area and get closer to the character, he looks totally visible, even though it's very dark in here. When I come out into the bright sunlight, I can still see him because auto exposure is taking over and correcting that dynamically. Also, in these very bright areas, they have a lot of bloom on them. It's this kind of bright, sunny day look and you know you can go ahead and tweak any of these parameters, however you see fit. But I've just setting you up with a number of effects to get started here. And I think that you'll agree that the game looks much more realistic and interesting with all of these effects happening altogether, so you can really make the game have distinct looks by taking advantage of post processing effects. 42. Commercial animated stationary characters: in this video, I'd like to import an animated stationary character from Render people. So this will give you an idea of a high quality asset that was created with the three D scan. And the animation probably was motion captured. I'm not sure it could have been key framed, but any of either way we haven't ah, high quality animation of this character standing in place, and this is a great way to add interest to your game by having characters that aren't moving around. But they're doing something. They look natural in the space. So to get started with this process, I'm going to extract the free animated people Zip file that I downloaded in an earlier chapter. And I'll just go ahead and overwrite the Pdf file that comes with the previous Render people asset. And then I can see in here that I have two different animated Zip files. Manuel and Sofia. I think I'll go with Sophia this time and I'll create a folder in here for that character because my Downloads folder is getting pretty crowded. So I'm gonna drag the Sofia Zip file in there and then go into that folder and extract this zip file in here so I can keep a better eye on the assets that are part of this particular archive. So now we haven't fbx file. We have an image of Sofia, and we have a texture. Some folder, which contains a bunch of texture maps. Great. Now let's get this into unity. I'll select the characters folder over here and create a new sub folder, three character name. Then I'll go into this folder, Sophia and then get the asset the Fbx file and dragged that in there and also go into the texture map folder and get the diffuse in the gloss and the normal map and bring them in as well. So there's a gloss map that comes with this, which I need to edit in Photoshopped To make this an Alfa channel. I'll double click on that. Open that and Photoshopped. And then just as a review, I'm going to convert this by selecting all copying it to the clipboard, making an Alfa Channel pasting that in, Go back to RGB, fill that with black and then save this as a file that has the words speculum her and gloss in the file name I'll save that and close it. And then back in unity, we should see the Photoshopped file appear. There it is. I'll select the model and go to materials and extract materials that are part of this. I don't need to extract the textures because we already have, Um, and then I'm going to go to rig and make this a humanoid and apply so that we can use it with the mechanism animation system that's part of our animator. And now I'm going to select the material and change its shader to the spectacular set up. And I'll drag in the diffuse map into the albedo slot, and I'll drag the Photoshopped file into the speculator slot, and the normal map goes into the normal maps lot. But it hasn't been tagged yet, so we can fix that just by clicking fix now. And that should be all we need to do in terms of the material. So then I'm gonna take Sofia and Dragon, drop her into the hierarchy. I'll turn off my 3rd 1st and player for now, and that switches us automatically over to one of the virtual cameras. And that's great because this virtual camera was set up to look at the character, and if I click on Sofia over here, I'm gonna I'm just going to rename her just with her name. And then the animator has her avatar already referenced. That's good, but it doesn't have a controller, so we need to make a new animation controller. I'm going to place that in the Sophia folder, so I'll I'll go ahead and create a new asset in there for the animation controller, and I'll give that the name Sophia. So with that selected in the Animator, you can see that we just have the default nodes, entry exit and any state. Now I need to get the animation clip that's part of this fbx file into this controller, and you can see that on the animation page. There's a clip in here called Take One, and it's also available here in the Project window. I'll drag take one into the animator, and Unity is smart enough to realize that this is going to be the default state, so it makes it orange, and it also automatically creates a transition from entry into the default state. That means that this will just automatically play There's really nothing else we need to do in this particular controller. It's a simple as it can get. So go back to the scene, select Sophia and then dragged the new controller that we just made into the controller slot in the Animator. And I believe that's always should need to do here. I'll go ahead and play and we'll see what happens. So she's animated. She is stationary. Look at that. She moves her feet over. She crosses her arms. She's just hanging out, looking natural. Let's watch the clip until it comes to the end. She puts her hand on her hip, crosses her legs, and then she actually stops because the clip comes to an end. So we don't want this to happen in the game because presumably would want this to just go on forever so we can loop the animation by going into the model on the animation page and locating the clip here. And, of course, your fbx file could have multiple clips. But we have just one here, and then it's listed down below, and what I'll Do is loop Time and Luke pose so that the animation will play all the way through, and then it will go back in reverse that we can kind of get double duty out of the entire clip. I need to apply that change, and now when I play, the animation should just go on forever. She'll go through these movements and go back the other way, and we could just pop her in a scene and it will add something and add this kind of dynamic entourage to a a game where you want to have characters that aren't actually doing anything , but they're just there to add realism to the game. 43. Custom animated stationary characters: in this video, I'm going to bring in a fantasy character that we created Infuse. And if you recall, we had a medieval kind of warrior who is having a business meeting, I thought it would be amusing to animate him in the context of a modern office. So let's bring him in. Here is the Dre our character, and he's having a meeting. That means the animation clip is part of this fbx file. So I'm going to go over into the Characters folder in the Project window and create a new folder with the character name that will go into that folder, switch back over to the file system and drag the fbx file into the character folder, and you can see the animation clip right here. I'm going to select this character and dragon, drop him directly into the hierarchy and let's see what's happening in the scene. So evidently he's far too large to fix that. I need to go to the asset here and change the model information. I'm going to change the scale factor well, unchecked convert units, and I'll put in a manual scale factor of 0.1 I'll just try that out by clicking apply. He's still the same size too large because we're not converting units. So what we could do is add another zero here in front of the one and click apply because he's probably exactly 10 times too large, and that looks like a fair assumption. Another way that we could do this is we could leave convert units on. And then we could just put 0.1 in here because convert units changes centimeters, two meters, which is already a two orders of magnitude change. Let's see if that's the same, I'll click. Apply. So it is. Either way you go, we need to scale him down by a factor of 10. And let's go ahead and turn off Sophia and focus on this Dre, our character going to adjust the position of sin Machine V Cam to by moving it. And maybe I'll view that here in the scene. And then I could just slide it back and slide it down so we can focus more on the seated guy. Okay, so now the next thing I'd like to focus on is the material and texture maps associated with this character. So to access that I'll select his asset, go to the materials page and extract the materials here in the same folder and also extract any texture maps that are part of this fbx file. Then I can select the material and drag the diffuse map into the albedo slot. And then the normal map goes in the normal maps lot. And we need to fix that normal mouth so that unity understands what it is. We have a speculum app here that we can't use in the metallic channel, so I'm going to change the Shader to the speculator set up, and then I'll drag this in here and drop it so he's too shiny to speculator. Want to decrease this down to a lower value, so he's not quite so glossy. Okay, so now he's looking good. The next step is to get him animated, so we have an animation clip that's part of the Fbx file. To make that work, we need to access the character in the hierarchy, and there's already an animator component by default that references this character's avatar. So the next thing is to create a controller that will play the animation clip, so I'm going to create a new asset here in the project Window will go to create en a meter controller and I'll call this Dre are. And then I'll select that in the animator window, which is currently just in the default state with entry exit in any state. And then I'll drag having a meeting comma meal into the animator window, and Unity will make that the default state. And it will create a default transition from the entry node into the default state. So this will automatically play now when the game begins. So I've created that asset, but I still need to reference it in. My characters all select him and then dragged. The Dre are animator controller into the controller slot here on Animator Component, and I'm also going to rename the character just so that has his first name with a Capital D . And then let's go ahead and play test the game and see if the animation plays and it does so in the next video. I'll show you how we can bring in some furniture so the character could be seated at a table and sitting on a chair 44. Providing seating for an animated character: Now that we have a seated character, we need something for him to sit on. So I'm going to access the exercise files folder, and I've provided an errand chair fbx file for you, which I created in Sketch Up Pro by going on to the three D warehouse and finding furniture , and I also have a desk model that we can use. So let's bring the Aaron chair directly into the Dre are folder, and then I'll select that here in unity and drag and drop it into the hierarchy and then double click on it in the hierarchy, and we can see that it's much too small. So I need to access the asset and go to the model page. This is so small that I think maybe it's off by two orders of magnitude. So the type of scale factor of 100 and then click apply and then double click on the air in chair in the hierarchy again to frame in on it. You know it's the right size. Go ahead and rotate that, and then it looks like I probably need to move it over a little bit, and I'm just going to navigate here in the scene, too. Examine the way that the chair arm rest is interacting with his left arm. It's gonna move this over, maybe back, and we have kind of an issue here where it doesn't quite fit. So what I recommend is potentially scaling the chair slightly to make it fit the character . Another thing that we could do is go back and diffuse and adjust the armed space toe, lift his arms up a little bit and re export the animation. But I think it might be more expedient here just to scale the chair down a little bit in the green direction by dragging this handle just slightly. And then I'm going to move this chair down so that the casters rest on the ground doesn't want to go too far so that it's sticking through the ground plane. And if you want to be really careful about this, you can go into an elevation view by clicking one of the cones here on this gizmo and then clicking on the word left to go into Ortho graphic mode. And then you can really see where it is in relation to the ground plane. So I'm going to go back and go into perspective again by clicking on the word I so and now we're closer to having a situation where the arm rest is okay. Maybe I'll move the chair back just a little bit. So he's such a big guy that he's gonna have to kind of be on the front of the chair. All right, now, let's take a look at how that looks here when we animate it. Before I do that, though, if the character has any route motion, that is, if his hips move it all, we want that motion to be transferred to the chair. Now. The way that we can do that is by selecting the character and making sure apply. Route Motion is on, and this will transfer any motion that the character has to its Children. So we need to make the Aaron chair a child of Dre are, by dragging and dropping that into Dre are because this is a prefab. This exists as an override and you can see that with a plus icon here, and that's fine. So let's go ahead and de select and play. So he's going through various motions and If you recall from Fuse, this is a lengthy animation clip where he does several different things. He it's like maybe he's having a discussion. And in the moment, if I if I remember right, he's going to type on a Nen visible computer we could bring in. Or we could cut that out of this clip. See, now he's leaning forward and he's typing on the computer. And I don't really wanna have a computer here, so I'm more inclined to cut out that section of the animation. Let me show you how to do that next in the next video. 45. Cropping an animation on humanoid rig: at this stage, I'd like to limit the length of the animation clip applied to Dre are. So I'll go to the asset in the project window, go to the animation page and scroll down where I can see the clip here having a meeting, comma meal. And here's the timeline for this clip. It lasts a good 40 seconds, so it's really lengthy. So if I go ahead and drag this, I'm not getting any visual feedback here about how the character animation is behaving. And I know from experience that that is not what we want. So the problem that we have here is that the rig is still set up to be generic, and we know that that actually worked the animation plays, but it doesn't give us the full functionality that we could have if this was a humanoid. So I'm gonna change that to humanoid and apply, and then I'll go back to animation and scroll down again. And now we have a more extensive interface here. Now that Unity understands that this is a humanoid that we're dealing with. So what I can do is dragged this end slider over and we get little graphs here for each one of these different categories, and we also have kind of traffic lights that show it's yellow, green or red. And it gives you an idea of how well of a loop that would make. So if it's yellow, it's maybe sub optimal and what we want to look for our green lights all around. And so the idea here is that for this duration, he's kind of doing the same thing. He's just sitting there having a conversation, moving his hands a little bit. But when we get into this region, that's probably when he leans forward and starts starts typing on the keyboard. So what I'm going to do is just drag this back into this zone. And then I want to say a loop time loop pose, and I'm also going to just bake the root, transform rotation and positions into the pose, and I'll click apply. And now, when I play the animation, he immediately kind of jerks when the game begins because the animation transforms or baked into the post. But that's not a problem, because we'll never see that when we begin the game, he'll already be in that pose and I'll just kind of be going through this sequence of events where he's looks like he's kind of bored. His hands were on the table, and maybe he's muttering to himself or talking to someone else at the other end of the table. And this is just gonna go on forever because we've decided to loop the pose, but he's never going to go over and type on that invisible keyboard. So I stopped the game, and the final missing piece here is a table, of course. So I'm going to go over to my exercise files folder and drag the desk fbx file in here. And let's bring that into the hierarchy and double click on it. And it's too small again by probably two orders of magnitude just like the chair. So I select the desk, increase the scale factor to 100 and apply, and now it looks like it's the right size, although it's not in the right place, so I just need to make some adjustments here. I'll rotate it, select it, hold down the control key to rotate it in set increments so I can make a 90 degree rotation and then I'll just move that over. It looks like this table is just slightly too high. So what I'd like to do is have it me just a little lower. So his hand is resting on the table. To do that, I'm going to non uniformly scale this in the green direction by drinking this handle down, as I do. That observed that it's shrinking it both from the top and the bottom. The center point is the center of this transformation, so I don't want to bring it down so it looks good on his hand because it's going to really make the legs short as well. So what I want to do is just make it about halfway and then move it down. And I can visually see where it's cutting into the ground plane there. And maybe I just need to make it just a wee bit smaller in the green direction and then move it down. Just a nudge more and they don't drag the desk into the Dre, our character. So it's also child it to him and then I'll go ahead and play. The advantage of doing that is that this desk will move with the character. Now if I want to change the relationship between the models and I can do that within here, could move the child to his hands, arresting on the glass. And then, if I want to move everything together, I could just select Dre are and move it all to some new location. Now, this wouldn't be a good idea if there was root motion where drink Dreyer was like rotating in his chair, because then the desk would also rotate with him. In that case, I wouldn't want the desk to be a child of the character. I'd like it to be a standalone object, So these were some of the considerations that you have when dealing with seated, animated stationary characters. 46. Bring in a new character to be driven by Ai: in this chapter, I'm going to build 1/3 person and character that's driven by an artificial intelligence algorithm. And so I'd like to create a new character for that. I'm going to use one of the characters that we imported earlier on in the first chapter, where we got the Render People assets when I extracted the free rigged people it brought in . Eric and Alison and I haven't used Alison yet, so I'd like to use her now. I'll go ahead and create a new folder with the character name, and then I'll put this ZIP file in there and go into the folder and go ahead and extract the ZIP file. And we're going to use the why Up t Pose version of the F Fbx file, and I'll just go over to the Characters folder and create a folder for Alison. Open that up and drag this fbx file in. We also have a text folder, which contains the needed texture maps. I'll get defuse gloss and normal and bring them in and then I'll select the character and drag and drop her into the hierarchy. We'll turn off Dre are and double click on the new Alison character, and I'm just going to navigate to get a better look at her in the scene. Now we need to rename her, so we just have her first name and then I'll select the asset here and she's at the right scale. So let's think about the rig. We want to make that humanoid. There are no animations on Alison, and we need to extract her material into her folder. We don't need to extract the textures because we already have them supplied in the ZIP file , so she already has her diffuse map in the Albedo Channel. And then we need to bring in her normal map and fix that. And then we can bring in the glass map, and that needs to be adjusted in Photoshop, so I'll go ahead and do that quickly. Select, all copied to the clipboard, making Alfa Channel pieced. Go back to RGB, fill with black Save as, and I'll call this spectacular and gloss. Incidentally, this procedure is something that's easy to automate in photo shop, and that goes beyond the scope of this course. But you can set it up so you just press one key and it does all of these steps automatically? Okay, so now we have a photo shop asset. I'll go to the material and go ahead and drag and drop the speculator in here. But I need to change the Shader to the speculator set up, and she's looking very good. So let's check her out here in the hierarchy. She has an animator component, and there's no controller on her yet. We're actually going to use the third person controller that we used with our player characters, but we can use that here for our AI character as well. But there are additional scripts that we need to add on to this character to make her function, and we'll do that in the next video. 47. Configuring components on Ai character: At this stage of the game, we have a new character with an animator, complete with an avatar and a controller, but nothing else. So let's access the needed script, which is part of the standard assets package. Open up standard assets characters, third person character scripts. And in here you'll find the AI character control, which is what we need. We can't add that directly to this right now because it's a prefab. So what I need to do is go over to the hierarchy and right click on the item here, Alison and say, Unpack prefab. And then I can drag the AI character control script onto this object down here at the bottom, where it turns into a blue bar. When I released the mouse button, many different scripts are added because they all are dependent on this AI character control. So we have that at the top, and it requires a target object, which we need to make. So I'm going to create an empty and I'll rename that AI target, and this is the place where the character is going to always be walking towards, and we can move that around in the game and if you get creative, you can have this move around with a script or with different techniques that I'm not going to cover in this course. I'm just gonna leave it up to you to go and add that functionality later, depending on what kind of game you want to make. But in this course will just be moving that target around manually in the editor. So this is the target that I need to bring into that script. So I'll go. I'll go back to Alison and then scroll down. And Dragon dropped the AI target into this target slot. So she's always going to be chasing that target, if you will. She has a knave mesh agent component. We need to configure that a bit. So I'm going to change the speed. This is how fast she walks. So if it was at 3.5, she'd really be sprinting all the time. I'm gonna sit that at one so she'll be running 0.5 would mean that she is walking. I'm also going to increase the stopping distance because if you leave that at zero, she'll never actually feel like she's gotten to the target and it will cause some kind of jerky motion when she gets there. So I'm gonna put a small value in here, say 0.1 meters. So when she gets within that distance, she'll stop and go into the idle animation. I'm also going to change her radius value to, let's say, 0.33 and her height will be 1.8 meters. I'll scroll down. We have a rigid body, which we don't need to configure. We have a capsule collider and we need to change that. So the height will be 1.8 meters and the center why offset has to be moved up half that distance, so I'll put in 0.9 to the capsule. Is this the shape here that as hemispheres on top and bottom, I'll change the radius to be 0.33? There's also a cylinder gizmo on her, and that is what we have here with the knave mesh agent. So if I change the radius value here, watch. That's the cylinder that's on her. So this is what the gizmo is that's interacting with the knave mash, just something that we're gonna make in the next video. So I'm gonna leave that at 0.33 and scrolling down. We have the third person character here, and I'm just going to boost the ground check distance 2.3 so that she can find the ground without any problems, and I think that's it. So in the next video, we'll go ahead and create a knave mesh for her to walk on, because as it stands right now, if you play the game, she won't walk anywhere. She'll just stand there in idle animation. 48. Building and refining the nav mesh: As I said in the previous video, If we play now, we're going to get errors because the character can't calculate a path because there's no now of mess yet. The nav mesh agent is throwing these errors, so I'll stop the game and clear the console. And the knave mesh agent component here works with a knave mesh, which we have yet to build, and that's can be done on the navigation page over here. So go to the bake page within this, and what we're going to do is bacon knave mesh onto certain geometry in the scene, so typically it would it would be baked onto static objects. So in this model we have the architecture, which already has all the static flags checked, and I'll just open this up and you can see that everything is selected here. I'll go to the ground plane and let's see what it has. It doesn't have anything set a static right now. I don't really want to perform a lengthy lighting light map calculation right now, so I'm going to leave light map static unchecked, and I'm going to check navigation static. Unlike the light map, this doesn't happen automatically, so no processing starts to happen. I'll also create off mesh link generation static, and that is related. And let's go ahead and now click beak and that will initiate this calculation process of creating the knave mesh. And right here there's a little thing here that says now smashed display, and we're showing the knave mash and it shows up in this blue color. All this navigate here in the scene. And you can see that that there's a mash now kind of draped over the geometry in our scene , and it follows specific rules that are set up here with these parameters, so it leaves a gap around objects. It's leaving a gap under the ramp here because the knave agent has a certain height of two meters so he can't fit under there. Eso it leaves a gap, and we can control the maximum slope that the characters can go up. And this is useful in the level. If you want to bring a slope up fairly steeply on the edges than your non player characters won't be able to go up there because the now mash won't exist in that area. So the idea here is that the NPC scan on Lee walk around on this blue mesh because we have changes in level. It's important that we also build a height mesh, and that's something that's under advanced. You have to check height mash down here and then click beak again, and the whole process has to be recalculated. This all has to happen before the game begins and the height mash will be displayed in pink . And you have to check that here. Now we can see the height mashes Justin pink if we show the knave mission and the height mesh, and we'll see that together. And so the height mash is necessary when you have changes in level like this, or the agent could get confused about whether there are under the bridge or on top of the bridge, for example. And so now I'm going to go out of the navigation window by clicking on the console just so that those colors disappear and then also like the AI target and reset its transform. So it's right now it's at the base of the character, and then I'll play the game, and this time we don't get any of those errors that are being thrown by the agent. Instead, I can select the target and then move that into a new location, and she's going to chase it. So this is what is meant by artificial intelligence. She's going to chase the target, and she's fairly smart. So if I bring it over here, she knows to go around. I bring it over here, put it back here. Depends. She might go that way, or she might go the other way, depending on which way is shorter. If I come over here and then move this up so it's above, he's going to attempt to go up the stairs. But she has a problem with that, and I'll show you how we can get around that in the next video. 49. Getting agents to climb stairs: the knave mesh that we created in the previous video is stored as an asset under the scene's folder. It is named with the scene name, So I have the scene's folder. I have the main scene, and then under there I have the main folder, which contains the knave mesh asset. That's what we're seeing. When we go over to the navigation window, you can see that now mash stored in here. If you look closely at the knave mash where it meets the stairs here, it looks a little bit lumpy, and that's because of the difficult geometry that we have here. And so the now of Mesh agent is basically having the same problem that we had with our user driven third person character player, and that is that they can't just can't get up the stairs. So we're going to solve this in a similar way that we did earlier with the third person player and that involves the hidden ramps. So I'm gonna open this up in the hierarchy and access the large ramps mesh. I'll turn on the mesh renderers and go up here and make this navigation static and also said it toe have off mesh link generation, which is something that will cover in another video. But it makes sense to make both of those flags checked at this point. Let's also do the same thing over here for mesh to which is hidden back here in the distance. On this lower platform, I'll do the same thing. I'll go ahead and check these two flags. I'm also going to adjust the agent radius and take a look at the scene here before I do that and noticed that there's kind of ah, certain offset that we have from the stairs. This is all based on the agents size agent radius. So if I change that to, let's say, 0.33 so it matches up with the agents. Actual sighs when we configured in another video also change the height to 1.8 meters to match up with the body. And then when I click bake, we're going to see some changes here in the mesh. It's going to go through and calculate that, and it's going to store that here in this asset, when it's done now, the process is complete. The mesh looks a bit different. It doesn't look lumpy anymore. This blue color is just nice and straight, and that indicates that the ramp is doing its job. I don't want to see the ramp in the game, though, So if I go over to the console to turn off the knave, Machin, the height mash, I can see the ramp and I'd like to go in here and make sure that the mess renderers are off . And then let's see if it works. I'm going to locate the AI Target, and I'm gonna move that here under this over paths kind of thing and I'll move it up above . So now she's going to try to get up there now play the game and let's see what happens. She is able to go up the stairs now because she's encountering them more like a ramp. So that's the secret here. It's the hidden ramp again that we need to configure for our AI agents 50. Creating off-mesh links: in this video, I'm going to discuss off mesh Link generation, which is an advanced feature within nav mesh geometry. And the idea here is there are occasions where you want your A I characters, too jump over the knave mash in an area where the mesh doesn't exist. That could be for a gap to jump over like a a chasm. Or it could be where they're going to leap down from one height down, toe, another height and so we can control both of those features here with drop ICT and jump distance. So in this particular scene, we have this structure that has a lot of places where we can jump off of. So I'm going to set the drop height. Now, we don't really have an occasion where we just have a horizontal gap that I want to jump over. And that would be where you would set the jump distance. So, in this case, I'm just going to avail myself of drop height. And I'll set this to one meter and I can re bake the mesh. But before I clicked, beak have to remember that I have those hidden ramps so have to go back and toggle on the mesh renderers or they won't be included. And then I'll go ahead and bake, and we're gonna see a slightly different result here in the knave mash. We're gonna see these circles on the ramps with arrows, and it points from the start to the end of this off mesh link. The idea here is that the character could take a shortcut. So now if you look at this, we have these off mesh links that were generated up to a height of one meter. If I had, ah, higher value here we get additional circles going up the stairs and the ramps. So these represent shortcuts that the non player character can take. Let's say they're running down the stairs and then they jump over here to save some time if they want to get over over in this area. So let's test it out and see how it looks. I'm gonna turn off the mesh renderers here on my hidden ramps and go back to the console and just clear that console out. And then I'm going to play the game and let's see, she's gonna run up the stairs on top and Now I'm going to move the target over here, and then I'm going to move it down in the green direction so that she has to get down below . When I do that, she's going to take a shortcut right there on that off MASH link. So that's the idea is it allows your AI driven characters to take shortcuts. 51. Making nav mesh obstacles: in this video. I'd like to discuss obstacles in the nav mesh. So I'll turn Andre are because then he'll provide a a nice obstacle. And right now he's occupying the same volume as our non player character, Alison. So I'm going to move. Dre are over into this area. I'm also going to move the AI Target from appear on the bridge down to the ground. I'll just change its Y value to zero, and then I'll move that target over here in front of Dreyer. So I'm gonna play the game and see how our NPC that's driven by the AI interacts with Dre are who's just sitting here. Zoom in and take a look. So if I move the target over here, she's gonna follow that target. And if I just move it over here, she walks right through him because he doesn't have a collider on him. So let's implement that. Next I'll select Dre are and at a component to him, which is a box collider. And then I'll go down here and click Edit Collider and just change the shape of this collider Inter actively so that it represents the volume of our character all this navigate over here so I can see the scrip on the other side and I need grip on the front as well. Pull that over here. I just have a volume that she she can collide with now. So then I'll turn off Edit Collider and again play the game and let's move the AI target over. And so now she runs right into that collider, and she's really trying to get over here to the target. But she doesn't really have a way around. As you saw, she kind of slowly moves along the edge until she finally gets around it. And then she runs over here, so that's not a very good solution. You can use colliders on static geometry like walls because the character isn't going to run against the wall because the knave mash is going to be offset from any walls like this is a kind of wall over here, and the knave mash is offset from that. So if I move the target over here, she's never gonna run up against the wall because she's smart enough to know that she can only go on the knave mash itself. But in a case like this where there's just a collider, she collides with it and isn't smart enough to go around. So because of this limitation, there's a different solution that we can implement here instead of just using a collider. So what, you're actually remove the box collider? It's not really working for us. So instead, I'm going to add a obstacle. The knave mesh obstacle component is like a collider innocence because it has a volume. It unfortunately doesn't have a button that we can. Inter actively resize this, but what you can do its position, the cursor over the letters X, y and Z. And so if I put it over X, I can then drag left or right to inter actively change that number. And in this case it looks like I need Teoh Center that a little bit forward in the Z direction to represent this volume that Dre are takes up. Okay, so now let's test drive this situation and see how it might be different. I'll select the AI Target moving over here, and she's not quite having the same behavior exactly, but she's getting stuck here. She is a little bit smarter about it but it's still not ideal. So if we look at the navigation page, you can see that the knave meshes just solid blue throughout their So she thinks she can get through there. But the obstacle is keeping her from walking right through Jr. So in this regard, it's fairly similar to the box collider, and it's not really a solution that's good enough. So what we can dio here is check carve. When I do that, it carves a hole in the knave mash, and the advantage here is that this will work even for characters that are moving. So if I play the game and move the target around, she's never going to run into him now. And she's never gonna have a problem kind of getting stuck there because the nav mesh doesn't exist in that volume or that area, rather, and additionally, if I move, Dre are to a new location. When he stops, the mash gets carved. So that's the idea here, yes, to be stationary. And as soon as he stops, the knave mesh gets carved, and so that could be useful if you have it on another player, because when the player stops then it carves the knave bash, and then then NPC is don't run into that person. Of course, you can run into an NPC using a capsule collider, and the two characters will bounce up against each other, push against each other, and that's one way that you can keep them from self intersecting. But this is a more robust solution here with the knave mash obstacle, and it kind of gets around some of the problems that you've seen with the regular colliders . 52. Implementing high-cost areas for the Ai: I'd like to discuss a way that you can cheap the behavior of your AI driven, non player characters. So, for example, right now, if I move the AI target around, Alison can just run circles around Dre are, and that makes sense because she's just running around on the knave mash, and there's nothing to discourage her from going in any areas. But let's say in this game, I want her to preferentially go around. Dre are in this wide open space, but only rarely, if ever go through this narrow corridor between Dre are and the ramp. So to build that type of functionality into the game, we need to create an object that will represent that area. And I'll begin by creating a cube object for that purpose. And I'm just going to reset its why. Coordinates zero by typing that in So it pokes up halfway through the ground plane, and I'll just kind of roughly position it here and then re scale it by positioning the cursor over the letters X and Z and just making it wider. I'll go over to the navigation window and take a look at that. It's necessary that this object span this width here in blue. It needs to be wider than that. Even a tiny, slender sliver of that blue will be enough to defeat this purpose. So we need to make sure that this new object is going to cover that up. And it sure does. I'm gonna move it down in the Y direction so it just sticks up above the knave mesh slightly. And now I want to designate this as, ah, high cost area. To do that, we need to make this object part of the knave mesh. So to accomplish that, we go to the object page and we need to start by making it navigation static. And you can either do that over here in the Inspector like you've learned how to do before or as a matter of convenience, you can just toggle that flag on and off right here next up. We have to specify this objects navigation area, and you can choose from these three built in categories. But what of those mean while we can find out if we go over to the areas page and they're listed here as built in areas so walkable and not walkable have the same cost and it's really more for organization purposes. Jump has double the cost. But I'd like to designate my own area and I'm just gonna call that high cost area and I'll give that a cost of five. And so that means that the AI is going to calculate this distance is five times longer than it really is and that will play into the eyes decision making process about whether or not to traverse this area based on that length. Next, go back to the object page and change the navigation area of this cube from walkable toe high cost area. And you might think, OK, I'm done. But actually, you're not done yet. We need to bake this into the mash or it won't have any effect. So I go to bake, and before I clicked Bake. I always like to remember that I have these hidden ramps and they're going to be excluded from the mesh unless I toggle them on. So I'm gonna turn them on now and then bake the mash and so no changes. We're gonna happen on those ramps, but we're gonna have a different color over here on this object when the baking process is done. In that color, we'll match up with whatever it says here. For user three, it looks like it's a pink color, and now we see that in the mesh. Now I can go ahead and tuggle off the mesh render components for my hidden ramps, and I can also toggle off the mesh render of this cube object because I don't really want to see it in the game. The pink color is still there, though. All this Rename this cube and call it high cost zone. Get out of the navigation window and play the game. Let's see how this changes the behavior of the AI driven NPC. So I'm going to select the AI Target and move it over here. And then I'm gonna quickly move it over here. And you see, she made the decision to go around the long way because internally in the AI calculations, it's multiplying the distance here by five across this zone. We can see that here in the navigation, so that really is five times longer, so she's gonna make choices, too. Always go the shortest distance, and in this way you can shape the behaviors of your MP sees by implementing these high cost areas. If I move this into this area, she's gonna go through there because there's no choice about it, even though it costs five times more. Her ultimate target is in that area, so she has to get in there. But if I move this around and jump over that distance quickly, she can actually get there faster by going the long way around. 53. Abstracting NPC for use with other skins & avatars: in this video, I'd like to show you how we can use another skin and avatar as our ai driven, non player character. Right now, Alison is set up to be that character, and she has numerous different scripts on her that make this possible. So what I'd like to do is create a brand new AI NPC object. So I create an empty and then rename that and call it a i N P. C for non player character. And then I'll reset the transform on that. And then I'd like to copy the components that are on Alison into this new empty game object . And it starts out with an animator. And it references the third person animator controller that we used both for the AI NPC and the third person player. Making a mental note of that, I'll go back to the AI NPC in AD an animator component here, and then I'm going to add that controller by clicking the target button and selecting it from the list. And then I'm going to actually leave the Avatar as none to keep this generic, and then later we can specify a specific avatar based on the skin that we're using. So moving back to Alison, let's see what she has next. She has the AI character control script, so let's put that on here a swell and that is located under standard assets characters, third person character scripts. And then I'll drag the AI character control in here. And that adds numerous different scripts in here. The 1st 1 has a target, so I'll drag the AI target in there. And then I'd like to copy the parameters that we already set up for Alison that works so well in here. So I'll go back to Alison and copy the component inside Alison to the clipboard and then go to the AI NPC and paste the component values in here. Moving on, we have a rigid body that doesn't need configuration. We have a cap SoCal lighter, so we'll go back to Alison and copy that component. Go to the AI NPC and paste component values. Finally, we have the third person character script. Well, this copy that and paste it, and I believe that's the end of the list. So we have all the components that we need to drive this as an AI NPC. However, it doesn't have a skin or an avatar as yet. I'm going to navigate over here to the root of the Assets folder. And let's look at the pre Fabs folder. I'm going to drag the AI NPC node into the pre fabs folder, and now it's Icon turns Blue. Now that this exists in the file system, I can use it in other scenes. Now to use it in this scene, I need to specify a skin an avatar. Let's say I want to use Robot Kyle as my AI NPC in this game, So I'm gonna take Robot Kyle's prefab up here in this hierarchy and turn it on and drag that into the AI NPC as a child. This exists as an override now on the AI NPC prefab, and now I need to specify the avatar for this to make it work, and that avatar is located under models, characters robot Kyle Model, and there's his avatar on. Just drag and Drop that in here. And I think that's all we need to make this actually function. But we still have Alison in the scene occupying the same volume. And to be fair, she's just set up and rigged to be an AI NPC, but there may be occasions where you want to use her as 1/3 person player. So what I'd like to do is strip Alison down so that she just has a transform. And to do that, what I'll do is begin by removing the AI character control script. And then I'll remove the third person character and just work my way up removing each component in this sequence. That leaves her just with a transform. So she's like a skin now, and I should make her a prefab. So I'll go locate the pre Fabs folder, and I'll just drank her in there and drop her. So now she can be used either as an AI NPC or as 1/3 person player. Your choice. So now I'm going to turn her off here, and I'm going to also turn on my third person player, and I'll just move my AI character over a little bit in the scene and I'll specify the AI target over here somewhere. And now when I play the game, we're going to be controlling our third person player. But we can also see the AI player running around up there chasing after its target. And so, in this way you can easily use whichever characters you want in your game, because we've set it up at an abstract level where it's easy to swap out different skins and avatars. 54. Outlining the goal of the game: The goal of this chapter is to convert this simulation that we've been building into a playable game in most games need a way to win or lose, and if you think about it, we already have implemented a way to lose. And that is through the script on the third person player called Trigger Death by falling. So if we fall off of the platform all the way to the ground, we die and we've tuned the falling distance threshold to four meters so that if we jump off of the upper platform and land on the lower platform, then will survive. So I can think of a way to create a game by having the non player character chase us. And if we can lure them off of the platform and make the same jump, let's say they're not quite as robust as we are and they're going to die if they make this leap right here. Obviously, they would die if they jumped off of the upper platform, but so would we. So the hidden goal of this game is to actually figure out on your own that you can kill the robot by jumping off of the upper platform and landing on the lower platform with them hot on your heels so we can implement that by putting the trigger death by falling script on the NPC. So I'll go over to the NPC and open that prefab. And then I need to locate the script in question. And that's a custom script that we have at the top level here in the scripts folder. Trigger Death by falling and I can drag and drop that script over here into the bottom of the inspector. And let's tune that so that the falling distance threshold is, say, two meters so that the NPC isn't quite as robust as theme third person player. So if they fall more than two meters, then they'll die, which I think should be sufficient for them to die by jumping off from the upper to the lower platform. But we'll have to play tests that, to be sure now I'll go back to the main scene now. This game, as it stands, provides a way to win or lose. But it wouldn't be very fun because there's no threat right now. The robot can just wander around, and eventually, if we figure it out. We can lure him off of the platform and kill him. But we're under no threat from the robot. So in the next video, we need to figure out a way that the robot can kill us just by touching us. And in that way, it will be much more exciting because we'll have to run away from the robot and we'll have to have him hot on our heels here. But if the robot touches us, then we're gonna lose the game. So that provides an interesting mechanic of this chase that will be the basis of our game. 55. Getting the NPC to chase the Player: If we play test the game now, the robot will walk off into the distance and eventually stop when it reaches the location of the AI target. So it's not a very playable game as yet. We need to get the robot to chase the third person player. To do that, we need to move the AI Target into the third person player as a child so that when we move around, the target will move with us. But right now the target is often the distance at some arbitrary location. So the first thing we need to do is reset the transform of the AI target so that it's at 000 and it coincides with the base of the feet of the third person player character. Then I can drag the AI target into the third person player to make it a child object. That means that it will move with the third person player. It also has a plus Icahn, which means that it's an override on the third person player of prefab and that's fine. So I'm going to move the AI NPC over a little bit so that we have more of ah separation between the characters and now I'll play the game and let's see how the behaviour is different. So the robot is coming for us and if I move over here, you can look in the scene and see that the robot is following us. Now if I just hang out here and wait a second, let's see what happens when the robot reaches us. Looks like he just pushes us forward and this is happening because the robot hasn't stopped . It hasn't reached its target, so as far as the AI is concerned, it's still trying to reach that target. And it's moving forward and pushing us its able to push us because of the capsule collider that we have on our player. And the fact that we have a rigid body allows physics to operate and allows the robot to push us to get this to stop. The solution is to go into the AI NPC prefab, scroll down in the inspector and increase the stopping distance from 0.1 meters, 2.8 meters. And to make this more exciting, I'm going to speed up the robot from 0.5 to 1 is that it's gonna be running and then we'll go back to the main scene and play the game. And now the robot is running over to us and when it reaches us, it stops. Now, if I try to walk, we're getting this jerky behavior because and so what's happening? Is it when we move, it's continuing to follow the target, but that's not what we want in this game. We want to die if the robot ever touches us, so that will be very exciting. We'll have to run around away from the robot, and if we ever get hit by the robot, will die. So in the next video will create a custom script that allows the robot to kill us by colliding with us. 56. Getting a hold of the Player's Animator through code: if we play the game at this stage, the NPC will run over and stop when it runs into the player. So what we want to do is create a custom script that will kill the player when the NPC collides with it. So I'll get out of play mode and let's begin this process. I'll create a new script in the Scripts folder. It's a C sharp script, and I'll call it Death by Collision. Note that there are no spaces in the name and I'm using Camel case such that each word is capitalized. Now that I have this script asset on disk Aiken double click on it to open it in my default code editor. And so now I'd like to start coding this. I'm not going to actually use the start or update methods, which are part of mono behavior. You see, this is a class deaf by collision, and the class name has to match the file name, and this will automatically be the case if you create the script in the way that I'm showed you. But just be aware that you can't rename the class or the file name to be different than one another or it won't work. The colon here means that this new class death by collision inherits from mono behavior in mono behavior. Defines many different methods that are called at different points in the life cycle of the game and start an update are very commonly used. So they're put in here with the template, but we don't need to use them. So I'm going to highlight all of this code inside of the class and actually delete it. So now I'm going to give myself some space inside these curly braces and then press the tab key to advance over. And what I'd like to do is begin by defining a variable of type animator. And I'll just type an animator space and them semi colon. This means we're creating a new variable and him in lower case, and it's of this type animator. So what does that mean? I'll go back into the editor, and if we what I want to do is have this script be part of the NPC, so I'm gonna go into the NPC is prefab, and then I'm going to scroll down to the bottom of the Inspector and dragged the deaf by collision script in here and place it on the NPC. And so this script is going to apply to this game. Object. The NPC and the animator is this component up here. So I'm creating a variable that is of type animator toe hold information related to this controller up here because ultimately I want to call the death animation in this controller . So if I select the controller, go to the Animator Page. You may recall from an earlier video that we have a standing react deaf forward clip that we play during this transition, and that's called by this death parameter. So there's a death parameter here that when we trigger that the character will die. So I need to be able to call that through the script. So let's go back to the script and get a hold of that animator component now. To do that, I'm going to avail myself of a method inside of mono behavior called a week. And the advantage of a week, as opposed to start, is that the code is called before the game begins. In the instant after you click, the play button awake is called, So I'm gonna just type in the word awake here and press enter and it will automatically put in this formatted method. And so this reads as private, which means the access modern modifier is private, and that means it's only accessible here Within this class. Its return type is void, which means it doesn't return anything at all. The method name is awake. It doesn't take any parameters. And whatever we put inside the curly braces now, well, that will be the code that's executed the moment the game begins. So this is where I'm going to place the definition of this variable animal type and him equals. And then I'm going to want to get a hold of the player. I want to get the players animator component, not the NPC, because ultimately I want to kill the player, not the MPC. So I'm going to say game object with a capital G and not to be, uh, mistaken with the lower case G. So I want the Capital G because that's the class. So I'll click on that and then I'll put a dot to access the methods that are part of the game object class. All the objects that you see in the hierarchy our game objects. So we have some certain methods here that are common to all of those game objects, and you can see in this kind of a short list of methods that you can use. What I'm looking for is find with tag, so I'll click on that, and this is helpful. This is an easy way to get a hold of the player, because going back to the editor, I'll go back up here to the top level into the main scene and click on the third person player in an earlier video. We set the tag of the player to the word player with the idea that this would make it easier for us in the future to get a hold of this object through code. And now we're at that point where we need to do that so we'll go back into the code. And so here we're gonna find with Tag and this takes an argument. So open up the parentheses and then put a quote in there and type in the word player just like that. So it's going to find the player now using the tag and So now we can imagine that we have the player now in memory. And so now, now that we have the player, I want to get its animator component. So I'll put dot to access methods that are part of the player and I'll use get component. It's the first method here and then get component is a special method that requires that you use a type and use a type with angle braces like this. So the type I want is animator the type of component. Then I'll close the angle brace and then I This method doesn't have any arguments. All open and close the parentheses and then terminate that line with a semi colon. In all, the red underlining disappears, meaning that there's no errors in my formatting or logic. We have the animator component from the player in this variable and him, and in the next video, I'll show you how we can use this variable to trigger the death animation. When the NPC collides with the player 57. Logging NPC's collision with Player to console: continuing on from the previous video. I'd like to continue working on the death by collision script, so I'll locate that in the scripts folder and double click on it to open it in my code editor. So right under the awake statement here, I'd like to add another method that's part of mono behavior. It's called on Collision Enter. So just start typing on and then let her see. And already I see it here at the top of the list on Collision Enter. So I'll click on that, and we get this signature here that shows that it's private, meaning that this method is part of this class. It can't be accessed from outside the class. It returns nothing. That's what void means. There's the method name on collision Enter, which is part of mono behavior from which all of the game object code in unity derives. And then this has an argument called other. It's of the type of collision. So the idea here is you can use other to get access to whatever object collides with your NPC, and if you're call death by collision is on the NPC. So what I'd like to do is get ahold of the player if we collide with it, and I'll do that through the other variable, make a conditional statement that checks to see if we are colliding with the player. It's all type If and then I'm gonna open up the parentheses and whatever arguments are inside, these parentheses have to resolve to either true or false, and if true, we'll go on from there. So the argument here that I want to check in if is other dot and this allows us to access the methods that are part of whatever object that we collide with. So in particular, I want to check to see if this game object that we collide with is tagged player. So I'll click on game object with a lower case G to get the actual game object that we collide with and then dot and then I'll use tag. And I'd like to check that tag to see if it's equal to so I'll type equals, equals. And that's an operator that resolves to either true or false, and that's appropriate here. Within the argument of this conditional statement, we're checking the tag of the game object that we collide with with a string. So strings have to be inside of quotation marks and that string will be capital player. So the way that we read this is if the others tag is player than this is true. And so then whatever follows after this, if statement will be executed. And so whatever I put in here is going to execute on Lee if we collide with the player and Patrick in particular. So before I put any more code in here, I'm just gonna think about I want to check to see if this works first. So one way to check is to use a debug log statement so that we can see in the console whether or not we're thinking this through properly. And it's working so far. So in a type, debug don't to access the methods inside the debug class in the method I want is log. So I want to use the debug log method which takes a parameter in the form of a string, which is a message. So the string has to be in quotation marks and Aiken type any type of message that here that I want to appear in the console so I'm gonna say something like NPC has collided with the player, and then it automatically closes the quotes and closes the parentheses. But at the end of the statement, I have to put in a semi colon to terminate that line. So now let's think this through again. So this method on collision enter is called when the NPC collides with another object. What we're doing is checking to see if that other object is tagged player. And if it is, we're gonna log this string to the console. So I go ahead and save this now and switch back to unity and play the game. And so now the robot runs over to us and nothing happens. And the actual reason is that the robot it's probably has probably stopped short of technically colliding with the player, and that has to do with the size of their capsule colliders. So watch what happens if I move over with the up arrow towards the robot. It actually triggers that message. So this is a question of tuning, but we have to do now is make the robot stop a little bit closer to the player, and if you're call that's done through the knave mesh agent script Soto access that I'm going to go into the NPC and just change the stopping distance to be a little bit less. Let's say 0.7. Let's see if that works. I'll go back to the main scene. I'll have clear on play selected here in the console so that when I play the game, all the messages will be cleared out, and now they're cleared out, and now we get that message automatically without having to move it all. And that's what we want. We want this to happen as soon as the robot hits us, and then in the next video, we're gonna add one more line of code that allows us to die and play the animation clip of the death animation when this gets triggered. 58. Stopping the NPC and killing the Player: At this point, when we play the game, the NPC will run over to the player, and when it collides with the player, we get a message log to the console, telling us that the NPC has collided with the player. So the consul has helped us to see that the code that we've written so far is working properly. But at this point, I'd like to implement some extra code that will cause the player to trigger the death animation. And if you go over to the animator, we have this death clip that we want to play and that will come out of any state. And that's triggered by this transition here. And the transition has a condition called deaf and death is a parameter, which is a trigger. Let's just keep that in mind when we're coding, so I'll go back into the code now and I'll place a blank line after the debug log statement Hear what I want to do is get ahold of the animator component that's on the player, and that's what we got earlier when we wrote the awake statement. The variable anim now has the players animator component in it and That's the way that we can access the death trigger. So I'm gonna type in him dot and I need to set that trigger soul type s for set. And then right in here, you can set a boule or set afloat. And if you scroll down, you'll find set into juror set trigger. That's what we want. So we're going to set the trigger and the set trigger has a argument which takes a string and the string name is death, and I need to put that string in quotes and then terminate the line with a semi colon. So this should play that death animation. That's part of the animator component. Let's go ahead and save and then go back to unity and play the game. See what happens now, so we start to die. But what's happening here is as the player dies, he moves over a little bit. His his room, his route transform, is moving over because he's falling forward. And, as he does that the NPC ai is trying to move forward. It's always trying to stay within 0.7 meters of that target. So we have this really weird thing that's happening right now so that we need to fix that by telling the AI to stop trying to move forward. Um, after we killed a player. So what we need to do is alter the way that the NPC is functioning and in particular, what I need to do is alter the way that the knave mash agent on the NPC is functioning. And there's no parameter in here that's accessible in the inspector that we can use for that. But nevertheless, these components have additional methods and properties that you can access through code. So I'll go over here into my script and then I'm going to add another line of code before N m set trigger. So up here before we play the death animation, I went to get the NPC to stop trying to move forward. So what we need to do is access. The NP sees knave mesh agent component and because this script is part of the NPC, we have access to that directly. We don't have to resort to finding the game object with a tag like we did for the player. So I can just type get component in here directly because the NPC has the knave mash agent on it in the editor. Let me just show you what I'm talking about. So here's the MPC. It has the knave mash agent component on it. In addition, has the death by collision script on it as well. And that's what we're coating. So that's why I can just type get component here and get component is kind of a special class that requires that you give it a type, so you'd give it a type by putting in the angled braces. So the type that I want here is knave mesh agent in Camel case like that. So each word is capitalized and then close angled braces and then this doesn't have any arguments. So I need to open and close the parentheses, But notice that the knave MASH agent statement is some underlined in red. And that means that the compiler is treating that as an error right now because it doesn't understand what the knave mesh agent component is. And this is because it's not part of the default name spaces up up above the class. So right under here, I'm going to have another statement using unity engine dot A. I and then semi Colon. And so this lets Unity search through the name space. It's part of all of the AI components, and now it understands what now MASH agent is and it's no longer underlined in red. It's now continuing on from where I left off. I'm gonna put a dot here to access the methods that are part of the knave mash agent component. So here I want to access one of the properties someone scroll down here and in this area we have These is properties which are usually billions. So is stopped. Is the property I want to change, so is stopped. I want to set that equal to a bullion value of true. So this means I'm going to stop the AI from trying to reach its target. And then I'm going to save this and go back into unity and let's play test it again. So now we've told the robot to stop trying to reach its target first, and then we play the death animation. So that is working notice, however, that Eric is partially sticking through the ground and that is something that we can adjust in the next video 59. Offsetting the death animation: if I play the game at this stage, the robot will run over and kill the player. And so that's working well, except the death animation has the player sticking partially through the ground. Let's figure out why that's happening if you recall the standing react. Death Forward Clip is part of the Nicole model. This was exported from Mix Imo with this particular animation, and it will work perfectly for the Nicole model. But it needs a slight adjustment if we're using the Eric Skin and Avatar because Eric is sticking through the ground a little bit. So to fix that, what we can do is select this asset and go to the animation page and scroll down where you can find standing, react death forward and right here. Be root transformation position and why is baked into the pose and there's an offset parameter. So I'm gonna type in value here, and we're just going to see by trial and error what the offset has to be. I'm gonna try 0.1 just for a short distance and click apply, and then I'll play the game again. Go back to the scene and let's see what happens. Okay, so Eric has sunk even more into the ground plane. So evidently we need to use a negative value for the offset. So I'm going to scroll down here and put in a minus sign in front of this right here and then apply and then play again. And so now he's above the ground plane. Although I think he's a little high. He is kind of floating a little bit above the ground more than I would like. I'm seeing a shadow underneath his body, so let's reduce this value even less than 0.1. Let's say it's point 05 so half assed much apply and then play, and that's looking a lot better. I think that's more believable. So this is the kind of tuning that you sometimes have to do when you're using a different skin and avatar on a animation that you exported. Using a different character 60. Allowing NPC to take leap with off-mesh link: At this point, if I play the game, it's very difficult to survive more than a couple of seconds because the robot is running and we don't really have a chance to get away. So what I recommend is why you're testing this. You go into the NPC, is prefab and scroll down to the knave Mesh agent script and changed the speed back from 12.5 so that the robot will just walk and then go back into the main scene. And now if I play the game, I'll have more of a fighting chance to survive because the robot is just walking behind me and I can hold down the shift key and run, and I'm going to come up here onto the platform and you can see in the scene that the robots following me up here, no, wait till he gets close. And then if I jump off of the platform, I survive. But the robot doesn't follow me. He's going back the long way, and that's because at this point it's impossible for the robot to follow me and take that leap. If I go over to the navigation page, you can see the knave mash, and I'll just orbit around here and navigate. Zoom in over here and you can see that there's no way for the knave matched to connect here . There are off mesh links down below at the bottom of this stair and at the bottom of the ramps. And that's happening because when we created the knave mash, we used a drop height of one meter, so it automatically generated these off mash links. I could solve this problem by boosting the drop height up to four meters, and then we'd have off MASH links everywhere. But I don't want to go to that extreme. Instead, I'd like to craft the exact place where the robot can follow me and I to do that, I'm going to create a custom off mesh link so that that's what this video is about. To make a custom off mesh ling, we need to add a script to the architecture, so I'll goto architecture in at a component on that which is going to be called in off mash link. And this component has a start and an end in these reference separate objects, so we need to create those separate objects. Next, I'll just use cubes to represent the start and end points of this off mash link. I'll create a cube and then I wanna move that over and pull it up so I can see it here. And what I want this cube to be is more like a pressure plate. So I wanted to be a very thin square. So to make that happen, I'll put the cursor over letter. Why in the scale transform and dragged to the left and that will collapse it down to a small value. And then I want to move this into position on top of the upper platform, and that's a tricky proposition. If you're just going to be dragging the handles around. I have a tip in a situation like this, which is to use object snaps, and you can access that by holding down the letter V on the keyboard. And I'm continuously holding down the letter V. And as I do that, as I move the cursor around, you can see that I can snap to these different points, that I can drag this object over here and snap it onto the corner of the platform. Despite dragging. Now I have released letter V, and I could move this over that it's over the platform and I'd like this to be the start point of my off mesh link, just to call that out visually. Maybe I'll create a material for that over here. This is optional, but I'm just doing this so I can see it. I'll call this material red and just to keep it simple, just change the alb Edo color too bright red. And then I'll drag and drop this material onto the Cube. So I'm going to rename this and call it start, and then I'll duplicate that by selecting it in the hierarchy and pressing control D. And then I have a duplicate object, which I'll rename end. And then I'd like to move the end down below, onto the platform below. So hold down V and snap that to the top of that platform down below. And I'll just move that over and maybe center it more so. That's for my landing zone, essentially, and I just want to make sure that these air more or less lined up and it looks like I could move this start over a little bit in my case here. Okay, so now I'm going to go back into the architecture and I need to drag my start and end cubes in here. I don't want this to be bi directional. If it was bi directional, the robot could potentially jump from here onto the platform above. I don't want it to be that way so that the robot will have to proceed from the start until the end. And now, to make this function as an off mesh link, you'll notice on the navigation page that it shows up here. And what I'd like to do next is hide these objects. So I'm going to go to the start and turn off the mesh renderers, go to the end and do that as well. And the off mash ling is still there. So I don't have to re bake the mesh and we can see that this is going to work. Now all we need to do is test it out. So I'll go ahead and play the game and let's see if I can get up there that getting caught by the robot and I'm just gonna wait a minute and take a look at where he is in the scene. He's coming up the stairs right now. I want to give him a chance to get close, and here he comes. So I'm gonna jump off of here and let's see what happens with the robot. He's jumping, and because that distance is too far for him, he dies. Oh, and funnily enough, when he died, he ran into me. And I died, too. But that wasn't my intention. 61. Adding user interface with canvases and buttons: At this stage of the game, we have a way to win in a way to lose. We can win by luring the robot to follow us off of this jump. We can lose, of course, by being caught by the robot or falling off of the high platform ourselves. So it would be good to indicate whether we've won or lost the game on the screen. And so to do this, we need to build a user interface. It would also be good to have a way to restart the game. Should we win or lose without having to quit the application and relaunch it. So again, that can be accomplished by adding an element to the U I, such as a button that we can click on and restrict the game. So let's build our user interface and the way you start that as you go over to the create button in hierarchy, go under you, I and we'll start by making a canvas. The canvas is like a blank slate upon which you build the you I and we can see the canvas here already converging upon the origin point at the base of the third person players feet so offends in way out. Now in the scene, you'll start to see the whole Candace, and it's quite large. So this rectangle represents the canvas or user interface that we're going to build. It's aspect ratio matches the aspect ratio of the game window that we have in the editor. So if I resize the editor windows, see how the rectangle changes shape in the scene. I can also resize it this way, and it will get wider in the scene. So next up, I'd like to lock down the aspect ratio of my game window to match my intended output aspect ratio. So open up this menu here and choose 16 by nine, which is my target aspect ratio. And now, if I resize this, the canvas will get bigger or smaller in the scene. But it will always have that same 16 by nine aspect ratio. And so that will simplify things a little bit when we're designing the you I because we won't have to consider what will happen if the aspect ratio where to change. Okay, now I'd like to put something on that blank canvas, so I'm going to go up to create you, I and I'll start with a button. And so the button just comes in at some random location on the canvas, and it's currently anchored right in the middle. And that's what these arrows represent on the canvass. The anchor. I'm gonna pull the inspector over here on the right and doc it over here. So I have a little bit more room to work on the elements here, and then I'm going to anchor the button in the upper right. So to do that, I'll open up this anchor interface element, and then I can click on the upper right here. But before I do be aware that you can hold down, modify our keys to also set the pivot are also set the position of the item, and I like to do both typically. So I'll hold down Ault and you see how the icons change. Or if I hold down shift, the icons change again. And if I hold them both down, then they give me yet again another symbol. So holding Ault and shift down. I'll click on this upper right element here, and then I can let go of the modifier keys and close this, and so it's moved the anchor up there. It's also moved the position of the button to match it. And now I'm going to just adjust that over here in the erect, transformed by sliding it over an ex and sliding it down. And why a little bit. And if I re signs the game window, you'll see that it maintains its behavior of being anchored in the upper right hand corner of the game. No matter how big the window is, that's kind of the point of the anchors, so it works with different resolutions. All right, now I want to change what it says here. I don't want to just say button, So let's examine the hierarchy. An expand button observed that the button is a child of the canvas, and then there's a text element below that which is a child of the button. So I'll go to the text and change what it says here for the text script. And I'll say that I'll re type this and make it say Restart. Maybe I'll make that bold and I want the button to be a bit narrower, so I'll go back up to the button in the hierarchy and then adjust the width. Let's try 100 and I'll drag to the left on the word with two interactive Leary size that notice also in the hierarchy that we have an event system, and this was created automatically when we created the canvas, and this is needed for triggering events, which happened when you click the button and down here there's an on click area that will trigger an event, and we're gonna add a script to this later on. And that's how we cause the button to actually do something. Okay, now I want one other element here, which is a label that tells us whether we've won or lost the game. So I'm going to create a new element on the canvas. I'll go up here to you. I text and notice that automatically goes on the current canvas, and it comes in as a sibling of the button. So there's two different text elements here. The one under the button is what it says. Restart all this collapse, that for clarity. I want to be on this text item here, and I'm going to change what it says and if you look closely. It says new text here. That's kind of it. Some random location on the screen. So I'm gonna rename that and call it victory. And just to draw attention to that, I'm going to change the color and make it green and also make it larger and bold. So now I want to anchor that to some corner of the canvas. Maybe this time I'll anchor it in the lower left corner and I'll hold down, shift in old and click it down there. And then I can adjust the position by sliding it over in X and up in Why? So we have an indication that we want now. What happens if we lose? We could handle this in different ways, but in this game, I think I'll create a secondary canvas that will be used. Will toggle that on in a script. If we lose gonna rename this canvas to the victory canvas, and I'm going to duplicate that canvas now and then rename the duplicate Defeat canvas and then I'll tuggle off the victory canvas and go into the defeat canvas and expand it. And in there we're going to adjust the text and have it say defeat, and I'll also change the color to read. So now I'll talk all that canvas off as well. So in the next video, we'll start to build a script that will allow us to toggle on one of these canvases according to the events that take place in the game. And we'll also start working on building a script that allows us to restart the game by clicking that button. 62. Toggling defeat canvas on when NPC collides with Player: At this point, we have built canvases for victory and defeat, but they're both off, so I'd like to turn the proper canvas on under specific conditions. So, for example, the third person player can die in two different ways, either by collision with the NPC or by falling off of the platform from a height of four meters or more. So let's first deal with the condition of death by collision. So the death by collision script is actually on the NPC, if you remember. So I'll select the NPC and scroll down here in the Inspector. And there you can see the script doesn't have any user configurable parameters at this point. But I'd like to be able to get a hold of the defeat canvas so that I can toggle it on should the NPC ever collide with the player. So I need to edit this script, and then I need to figure out a way to get a hold of the defeat canvas, and we do that through a variable. If you want to access that variable in the editor, you need to give it a public access modifier. So I'll type public, and then I'd like to make this generic, so just call it a game object with a capital G, and then I need to give this variable a name. I'll call it Canvas with Lower Case and then terminate that line with a semi colon. Incidentally, when I declared the animator, I didn't put an access modifier on it. I just typed the class name Animator. But all declarations are private by default, so you don't necessarily have to ever type private. But you can if you just want to be explicit, so I'll do that for clarity. This allows us to differentiate these the access to these different variables. So now I'll go ahead and save this and go back into the editor. And let's take another look here at the death, my collision script, the bottom of the NPC, and you can see that now it says canvas, because this is public. It allows us to edit this variable here in the editor. So now I can drag a game object in here in particular, I want the defeat canvas, so I'm going to drag that in there and drop it. It appears in bold type, because this is now acting as an override on the prefab. We have a hold of that, but we aren't doing anything with it yet, so I need to go back into the code and right after we trigger the death animation, I want to turn the defeat canvas on. So I need to say canvas dot and I'll use the method set active and this method takes one parameter, which is a bull. So I need to make it true. And then I'll put a semi colon right after the closing, parentheses there and then save. Go back to the editor and then we'll play the game and see what happens. Now when the NPC collides with the third person character, we get the defeat canvas showing up. We also need to hook it up so that the restart button does something, but we'll hold off on that for a while. Yet as we still have to code other ways for the character to die or perhaps to win, we need to be able to display the proper canvases according to those conditions. So we'll do that in the next video 63. Differentiating between victory and defeat in code: next up. I'd like to deal with the condition when the player dies by falling or the NPC dies by falling and we're using the same script trigger death by falling on both characters. So let's take a look at it in the NPC, you'll see it trigger. Death by falling is here, and we have a falling distance threshold of two meters on the NPC and then on the third person player. We have the same script with a higher falling distance threshold of four meters, and that's what allows us to lure the robot off of the platform and ourselves not die, but the robot whose less robust will come apart and die, Uh, when they land on the platform. So what we need to do is differentiate between these two conditions because we're using the same script. We need to figure out how to trigger the victory or the defeat canvas within the code. So let's open up, trigger death by falling, and I can do that by clicking the gear icon over here. Or I could just double click on the script over here in the project window. Either way, we'll work. This is a script that I just gave to you and it didn't explain much how it works. And you may notice that we have this serialized field up here. So what we could do is either use a public access modifier or you serialize field. Either way will allow that variable to be accessible in the editor. Now it's considered to be better practice to you serialize field unless you need this variable to be accessible from other classes. So I'm gonna go with that best practices suggestion and use serialized field instead of public. And then I need to get a hold of the victory and the defeat canvases. So I need to variables, and I'm going to call them game objects. So with a Capital G, and I'll call this one the victory can this and I'm using what's called Pascal Case, where you have a lower case letter on your first word and then capitalized Second word or Third word. All the other words have to be capitalized in the variable name, so let's go ahead and add another serialized field. It's also of the type game object, and it will be called the Defeat Canvas. So now we have those two serialized fields I'll save. Go back over to the editor, take a look at the third person player and locate that script. And right here it's in bold because this is acting as an override on the prefab, and I need to drag the victory canvas in here and the defeat canvas in there. We also have to do this on the NPC, which uses the same script. So now I'll drag the victory canvas in there and the defeat canvas adjacent. So everything's hooked up, but we still need to code what happens? So we have these variables victory and defeat canvas. So I'll come down here and right here in the code. This is where we trigger the death animation. So I'm gonna add some white space after that. This is where I'm gonna add some additional code to determine whether it's the NPC or the player which is dying here. So I'm gonna say, if game object in lower case, because we want the actual game object, not the class. If game object dot tag is equivalent to the string player, then I'll put curly braces here and put my cursor inside of them. Impress return to move down to the next line. So now if the if the game object is the player, then if the player falls to his death, then we're gonna lose. So we need to set the defeat canvas active. So defeat canvas dot set active, which I'll make true what happens in the other case. If this was not the player, that means it's the NPC. So after the If statement in the curly braces, I'm going to say else and put in another pair of currently braces, move the cursor over one press enter. And then here in this case, I'll say the victory canvas should be set active, and that would be true. Okay, let's see how that works. I'll go ahead and save, go back into unity and play test the game. So I'm going to run up this ramp here and jump off and fall to my death. And sure enough, it says defeat. So that's working properly. Now I'll play test the game again, and this time I need to lure the robot off of the platform. So I need to run up here being careful not to fall off, and I need to get the robot to come up there and notice that the robot is getting stuck down there for a second. That's something all address in another video. So now I'm gonna wait till he gets a little closer, and then I'm gonna jump off of here and get out of the way and turn around and look at him . And it's victory for us because we've killed the robot and now kind of a strange things happening here as I walk away, even though the robots dead, the AI is still trying to get that tow walk over to me, and it's very odd that it's just kind of sliding along the ground. But what we need to do is get that ai to stop navigating. If the robot dies like that, so go back into the code. And now, just before the death here, you know, add another statement that will allow the robot to stop chasing us if it dies. So, um, let's see, I need to, uh, query the knave mash agent. So I'm gonna say if get component angled brace, knave, mesh, agent close angled brace, and then open and close parentheses. So if that component is not equal to no, which it would be if it didn't exist on that game object. So if it's not know, that means we have in a knave mesh agent and we're dealing with the NPC. If that's the case, I'm going to say, Get component now of mesh agent opening, close parentheses and then I'll put a dot toe access its methods and properties. And in this case, I want to access a particular property that begins with The word is and these air billions so is stopped. Is the property that I want access and it's indicated by a wrench or spanner symbol. So is stopped. And because this is a property and not a method, it doesn't take parameters. So we, if we want to make it true, we have to say, equals true. So in other words, if the game object has a knave MASH agent component, then we're going to say is stopped is true. And that should stop that ai from chasing us even after its debt. So go ahead and save that, and then I'll go back into the game and play again and again. I'm gonna lure the robot off of there and see what happens when he dies. Hopefully, he won't slide over to us like he did before. So I'm gonna just jump off of here and then turn around and see what happens. The robot is coming. It's jumping down. We win. And the robot Ai is no longer trying to pursue us in death. So it's all working great. So in the next video, we'll hook up the restart button so that we can do something after we achieve victory or defeat. 64. Refining the NavMesh for fluid Ai movement: At this point, the game is working pretty well, but I noticed that the NPC kind of got stuck for a second when it was trying to go up the stairs over here. So let's take a look at the navigation window and see if we can figure out why that's happening. I look at the knave Mecir, and you can see that the knave mash sort of overlaps here with the bottom stair. And I think what's happening is he's walking up here and he's actually getting stuck in this area. So what I'd like to do is rebuild the knave mesh to solve this problem. Remember that we have hidden ramps that we have to deal with whenever we're rebuilding the knave mesh. So I'm going to expand the hidden ramps fully and go to mesh one. And I need to go to the Inspector, which I'm gonna doc over here again and I'll scroll down and turn on the mesh renderers and then select mesh to and turn that on. We also have a NA object over here for the high cost area that I should turn on temporarily and then I'll go over to the bake page and change the step height to a lower value. Let's say point to that changes the rules from which the knave mashes generated. I'll click Beak and let's see what that does visually to this blue knave mesh. When the baking process is complete, I suspect that it will eliminate this little section here, and that will make the robot smoothly move up the ramp. And there it is. We have more of a gap there because we have a lower step height that's possible for the NPC . So now I'm going to turn off the mesh renderers for the high cost zone and measures one in two of the head and ramps. And so now I'll play test. The game will get out of the navigation window and play test the game, and I'm going to run up the stairs there and let's just see if the robot is going to have any trouble getting up the ramp. So now there's no hesitation there. It just goes right up, and it's a little bit more menacing. We can also make this much more challenging by increasing the speed of the NPC, I'll go into the NPC prefab and scroll down here and increase his speed upto one so he'll be running. Or if we want to make it a little more fair, let's make it somewhere between walking and running, Let's say 0.7, so it's a bit of a challenge, but it's not really difficult. And then we'll go ahead and play and now he'll be coming out. It's more quickly. I've got to run up here if I'm not gonna get killed right away. So it's a little bit scarier because he's coming for me that much more rapidly. And if I wait too long, I die so you can tune that parameter to set the difficulty level of your game essentially. 65. Building a GameManager class and game object: At this point, our game is working really well. However, there's one last thing to do, and that is to hook up the restart buttons to open the scene again. Should we either win or lose? And to do that, I'm going to implement a game manager script. And most all games have a game manager, and in this script, we can put any code that manages the game as a whole. So over in the Scripts folder, I'm going to create a new C sharp script called Game Manager, and any script of that name will automatically get the gear symbol. Unity understands the importance of this script, so it's treated a little differently just with the icon, and I'll double click on that to open it. And we get the template that shows the start an update methods. I don't need an update method here. I'm gonna get rid of that, and I'm also going to get rid of the comment above start. And just above that, I'm going to put in a bull variable that ill defined. Now it will be a private field called It will be of type of fuel, and I'll call it has game ended, and I'm going to set that to false initially. And then in start, I'm going to call a code routines all type start co routine. And this has one argument, which is the name of the co routine in quotations, which will be called End Game Loop. Now, underneath the start method, I need to define my co routine in all co routines. Must be of the type I in numerator I in numerator endgame loop. It doesn't have any arguments, and I'll open and close The currently braces notice that it has red underlying underneath the endgame loop. And that's because it's not really a complete co routine. Yet it must return something. And so we in a co routine, you have to use the yield statement for that. So I'm going to do that. But I'm going to couch that inside of a while loop that we can Onley break out of when has game ended is set to true. So the way that I would code that is, I'd say while and I'm putting an exclamation point in front of has game ended because I want to invert it from false to true so that means it starts out being false, and when we inverted, it becomes true, and that means the while loop will execute. So inside the while loop I'm going to put the curly braces and then I'm going to say yield , return? No. And what that does is it advances to the next frame. And so the while loop will repeat every single frame and it won't do anything, but it will be stuck in this infinite loop. We can only break out of the loop if we set has game ended two. True. And when we do break out of the loop, any code that we put after the wild statement will execute. So I'm gonna say I'm going to make a new method called restart level and that should show up in red because I haven't defined that method yet. I haven't said what it does so down underneath E co routine here. I'm going to define this new method restart level, and I'm going to make it private. It's not going to return anything, so I'll say, void and then restart level like that. And now they're red. Underlining went away because I have defined it and so now here is where I want to put the code in here to actually reopen the same scene that we're in. And to do that, I need to access a different name space above. I'm going to say using unity engine dot seen management That's necessary if I'm going to use scenes. So I'm going to create a new variable inside this method of the type seen and the variable name will just be lower. Case seen, and I'm going to set that equal to the class seen manager dot get active scene. So that gets the active scene, whatever it's called. In our case, it's called Main. So it's going to store that main seen in the variable scene. And then on the next line, I'll say seen manager dot load scene in which seen it has to come as an argument, and it will be the scene variable dot name because this has to be a string. And then I'll terminate that line with the semi colon. So this will so successfully get the scene name and then load the scene that that scene essentially restarting the game. And this will happen only if we break out of the loop here, and we can only do that by changing the has game ended variable. But we won't be able to change this variable because it's private. And so, technically, this is called a field. What I'd like to do is make a property out of this field, so properties, air public and that will allow us to change this value. That's private, so this will be a public pool. Properties often use the same word exactly, except it uses a capital letter. So has game ended is the property name. So in that I'm going to use a getter in a center. So first the get statement has to be inside of the Carly braces also get. And then I put another pair of curly braces in there, and this is what happens when you query this property here. You want to get, whether it's true or false, and we have to return the field name has game ended, and then after those curly braces on, I want to have the ability to set this property to either true or false. So I'm gonna say set and put another pair of curly braces and then I'll say, house game ended equals value. Value is a special key word that works in this context, so I'll go back into unity and consider that we've just made a class here called game Manager. But it actually isn't going to do anything at all yet I need to also create an empty game object in the scene, which I will also call. Game manager could have any name, but just for clarity. I'm gonna call it that, and I'll reset. It's transformed to the origin point, and then I'm going to put the game manager script on that object. In that way, the game manager code will be loaded as soon as the game begins because it's on a game object in the world. Okay, so now we have the script that we need, and now we just need to figure out how toe connect it to the buttons in our canvases. And I'll do that in the next video 66. Connecting Restart buttons to setting bool Property true: Okay, now the game is almost complete. The last thing that we need to attend to is to connect the restart buttons in the victory and defeat campuses to the property that we coated in the previous video in the game manager. So to get started with this, I'm going to select the button in the victory canvas. To start with, I'll scroll down in the inspector to the button script and right at the bottom of that button script. You'll find this on click area, and this is responsible for making events fire so I can cause an event to fire. And that's going to be fed through the event system automatically. And when we have that event, we can trigger a property or a method that's public on a game object. So I'm going to add to the list, and the way that this interface works is you have to use. You have to drag a game object into the slot down here where it says none, and you might be tempted to drag the game manager script in there directly. But I don't recommend that because we don't have access to the code that we need here So instead of dragging the game manager script in, we need to drag in the game manager game, object from the hierarchy in here. If you do it that way, then you have access to the game manager component, which exists on the game manager object. So let me just go to the game manager here and you can see that what we're accessing is this component, which is actually the script. So I'll go back to the button there. And now that you understand what we're accessing, I'm going to choose game manager component. And within that I have access to the has game ended Property fields will never show up in this list. And so that's why I went to the trouble of creating a property that we could access in this way because it's a bull property. We have a check box, and so we want to set this to be true. So I need to check that. So when we click on the restart button, it will set the has game ended property to true and looking at the code, what does that actually do? So here we have the property. When we set that true comes in as the value and that is assigned to the has game ended field in the has game ended field is what is responsible for keeping us in the while loop. So when that's true, the while loop will become false because of the exclamation point that's here and that will break us out of the while loop and execute the restart level method and the restart level method actually reloads the scene. I'll go back to unity. We need to have a similar on click event on the defeat canvas. So I'll go to the defeat canvas button at an event here and that will be triggered by the game manager. Object in the hierarchy. And that will access it's game manager component has game ended. That will also be true. So now let's go ahead and play test the game and see if my logic is sound. I'm just gonna hang out here and wait for the robot to catch me. I'm defeated and now click restart and it worked. So now I'll go up here and run up the ramp, try to get away from the robot, and I'm gonna lure him off the ledge here to jump down, get out of the way. And it's a victory for me because I've killed the robot and now I can restart and the level begins again. So now we have all of the elements of a playable game. In the next chapter, I'll show you how you can use a game controller to make this game much more fun to play. Because if you have an Xbox one game controller or a PS four game controller attached to your computer, then you have those analog sticks that will allow more subtle movements, and you will map the different functions of the game, like jump or crouch two buttons on the game controller itself. 67. Connecting controller and testing in game: If you've purchased ah, game controller, you need to connect it to your computer. In my case, I'm using a wireless Xbox one game controller, so it connects through Bluetooth and I'm on Windows 10. So I'll go into devices and then I'll click on Add Bluetooth or other device. And then you also have to click the button right on the front of the game controller right here to go into the mode where you can discover the Bluetooth device. And once that happens, it's pretty much automatic, and I'll turn this on here and you'll see that the Xbox one wireless controller shows up. Now, if you're using a different game controller or a different operating system, obviously the steps will be different. But the point is, you need to make a connection to your device first and then go into unity and you'll see a message down here that says, Joystick reconnected. Now I can go ahead and play the game unless you see what happens out of the box. I'll move the analog stick and I can walk. But I'm caught pretty much right away by the robot because I don't yet have the ability to run. All I can do is walk and I can't move the camera around, so we have a lot of configuration to do before the game is really workable. 68. Mapping the Fire2 axis to run: At this point, I'd like to implement the ability to run on the controller, because right now I can only walk with the left analog stick and I get caught by the robot very quickly. So I'd like to be able to press a button on the controller and allow me to run. So we need to think about how that's implemented. I'll go to the third person player, and if you recall from an earlier chapter, it's the third person user control script that is responsible for the character walking or running. So I need to access that and edit the script and scroll down near the bottom. There's this section here that we edited in an earlier chapter where we enabled the character to run by either holding down the left shift key or the right shift key. I want to add in another or statement here so that we can have a button on the game controller that will allow us to run. But this is getting pretty confusing with all these nested parentheses. So what I'd like to do is just format this by adding in some white space here and using the tab key just to indented things, and I'm just going to clean this up a little more so we can make more sense of it. So now we have these two clauses of left shift or right shift. I want to add another one. So I'll say or and then at another line down here, that will be some kind of way to access the button on the game controller. And that's done through the input manager in unity. So I'm gonna just pause here and come back to that. I'll go back into unity and open up the input manager, which is part of the project settings now in this version of Unity. So edit project settings and then click on input. And then you have this thing here for axes, and there are 18 different axes that Air said that by default. And so, for example, horizontal and vertical are used by this script to move the character around. And that's done with the left and the right arrow keys. Can the up and the down arrow keys. Alternatively, you can use the A and D keys to move left and right, or the W and S keys to move up and down. And so that's working great. And we already have this automatically mapped to our left analog stick on the controller. That's how I'm able to walk around. But now I want to access a different axis here, and I'm tempted to use one of the fire axes. So let's take a look at Fire one and Fire one is triggered by the left control key on the keyboard or the mouse zero button. That's the left mouse button so I could click on that left mouse button and it'll allow me to run, Let's say, or I could use fire to if I wanted to use the left Ault Key or the mouse one button, which is the right mouse button, um, so that those are possibilities. But I want you to have also observed that down below. Here there's additional fire ones and fire twos and fire threes and those air already pre configured to use a joystick button zero and joystick button one. So we need to figure out what those map to you. It's the best way to do that is just to do a search for your controller, say Xbox one. Controller unity, mapping and I found a diagram here, which I'll give you the URL to. That shows this mapping in great detail both on Windows and on Mac OS. So if you're using a PS four on the Mac, you'd want to search for that and find a diagram that shows this mapping. Now. I'm interested in getting the B button here on the controller mapped to the ability to run , and that would be but be here in a in this area. And so that's map to joystick button one on windows. Interestingly, on the Mac, it's joystick button 17 so it really varies by operating system and controller. That's why the finding a mapping diagram really will save you a lot of time. In my case, I want to map it to joystick button one. So going back to unity, that would be this one here. It's already mapped to fire to the Axis called Fire, too. So let's just keep a mental note of that. We want to use fire to. I'll go back to my code editor and then I'm gonna type in input dot get, And here we have different choices of what we want to get we don't want to get the whole axis because that would return a value that would vary from 0 to 1. I want to get the button and the button returns a bull. It's either pushed or not. So I'll say, Get button and then the button in question will be identified with a string. So I have to put quotes I'll type of fire to, So that should do it. I'll go ahead and save that. Go back into unity, move the just close the project settings. For now, I'll clear the console and let's test the game. In this time, I should be able to press, be now and run and it works. And it's interesting that this when I'm running, I'm actually using a lot more of the animations in the blend tree in the animation controller and I have much finer control over my movements here using the controller. Then I did previously using the keyboard, so this makes it more exciting. And because I do have such control, I might be tempted to increase the speed of the robot up to a value of one. So it's more of a challenge, so I'll just do that now I'll go over to the in PCs prefab and change the knave. Mesh agents speed toe one so it's more challenging, and I'll go back up to the main scene. So in the next video, we'll show you how we can map some other behaviors on our third person character. Two buttons on the controller. 69. Mapping the Fire1 axis to crouch: now I can play the game and I can run around by holding down the Beaky and just pressing the different buttons on my controller. If I press why Aiken jump and the robot caught up to me there, so I'll restart. So now I can jump and I'm not jumping very high, so I might want to tune that. And I have no way of crouching at this point. So I'd like to implement the crouch ability so I could go under here and hide from the robot because there's no knave mesh under that area. And if I go under there, it's like a safe zone I could hang out in. Okay, so the first thing I want to do here is adjust the jump height, and that's actually part of the third person player, third person character script and the jump power is currently set at three on a boost that up to 10 and see how that is different. So I'll go ahead and run and then jump you and I can jump really high. Maybe that's too high. All set it at Maybe six point is you have to tune your game after doing numerous play tests gonna run over here and jump, and that's better. Can really do a leap like that. And I don't jump so high that when I land, I die. And that's a good thing to Okay, so that's working well. But now I need to figure out how to crouch. So let's go and edit the same third person user control script that we were just working on in the previous video. And if I just scroll up a little bit here, there's a bull called Crouch that is triggered by the Keesee on the keyboard. So what I should do is add in another possibility here. So to do that, I'm going to surround this part of code with parentheses before the semi colon. And then in there I'm going to put in or statement and I'm going to say input get and I want to have a button in this case, ideally to crouch, I'd like toe have button A on my Xbox one game controller Trigger this so this will be get button and then I need to have a parameter with some kind of string that will name this axis, and I don't yet know what that access is. So I need to figure that out. So I'll go to my mapping diagram and I'm talking about Crouching. So I want to use the A button here and on my platform that turns out to be joystick button zero. So armed with that knowledge, I could go back into unity and reopen the Project settings window. And then I can figure out what Joystick button zero is. It turns out that's Fire one, the Axis Nunes Fire one. And if you wanted to map joystick button 17 or something in here, you could just change the text in here to whatever button you need to map to. So, uh, I'm happy with joystick button zero. It's access fire one. So go back to my code and type in fire one here, and that should be enough to get crouched to work. I'll go ahead and save that and play tested. I'll quote this project settings and clear the console and play the game. I'll run around and press the A button, and I Crouch works great robots right after me because he's a lot faster than he was before . But now I'm in a crouch and go in here. Look at that. I'm I'm ableto hang out in here in a safe zone where the robot can't get me because there's no now have mesh in there that provides another interesting mechanic in the game being able to hide for a moment and gather your wits about you. But I have no way of looking around. I can't move the free look camera, and that will be the subject of the next video is mapping the free look camera to the other analog stick on the controller. 70. Mapping analogue stick to Cinemachine FreeLook camera: At this point, I have crouch jump and run, mapped to different buttons on my game controller and I can also walk by using the left and a long stick. But I'd like to be able to control the free let camera rig by using the right analog stick . So I'm gonna look at my mapping diagram. And here's the right analog stick that I want to use and that's controlled over here by the RS Underscore H and V and that in this diagram that would be mapped to the fourth and the fifth axes. And that's the these air axes that return values from negative one toe, one in each direction, and so that's needed to control the camera. And if you are on the Mac platform, they would be mapped to the third and the fourth axes. In my case, I just need to make Make a mental note to use the fourth and the fifth. Okay, so now go over to Unity and expand the third person player. Click on the Sina machine free look camera, and if you scroll down here into the center machine free, let camera script under access control. We have a y axis and an X axis. And those air currently mapped to the mouse Why and mouse X axes. So if we go and look at the infant manager, you have mouse, X and mouse. Why? And what we could do here is create additional axes that don't yet exist. So I mean, it just collapse everything. And then I'm going to increase the array size here from 18 to 20. And what that does is it adds a couple of more axes down here, just copying the last one. So I open this one up and I'm gonna rename it and call it stick necks. And I don't want it. Teoh be the escape key or this kind of thing. Get rid of this information in here and we can control the sensitivity. This might be important. I'll set that at one by default, and then we need to choose. The type is going to be a joystick access, and that will be the fourth or fifth access. I'm not sure I'll try the fourth axis and let's just look at our diagram again. So the H value is horizontal, and that would be the equivalent to the, um X value. And so that would be the fourth axis. Okay, so this seems to be mapped properly. Now, I'll open up this last axis and rename it stick Why? And again, I'm going to get rid of these elements here. But I will send the sensitivity at one. And then I'll change the type to a joystick access, and that will be the fifth access. Okay, Now I'll close the project settings window and change the input access name here to stick why? And this one to stick X And let's see if it works. I'll play the game and I need to run away pretty quickly or I'm gonna get killed. But now I can use the other axis and it does work to move around. And in order to find Tunis, it would be useful if I didn't have to always run. So I think to play test this. I'm just going to turn off the AI character temporarily. I'll just start the game with him off, and now I'm under no threat so I can take my time. So now here I am, and I can move this around by using the right joystick, and it is very quickly, perhaps too fast for my liking, and it also when I'm not even touching the access, it's doing something it's orbiting up into a certain position. So in the next video, I'll show you how we can find tune the way that the sinner machine camera rig works in with regard to the axes. 71. Fine tuning how analog game stick controls camera: when you play the game, the chances are very high that the camera will seemingly move of its own accord like it is for me. I'm not touching the analog stick it all right now, but it's moving around and let's figure out why that's happening. I'll scroll down here in the inspector while the game is playing and look a access control . And then I'll click in the game window to set the focus on that. And I'll use the right analog stick. And as I move that around, you can see the input, access, values or changing here. And now I'm going to release the right right stick and not touch it at all. And we have these very low numbers in here, and that is why we're having this movement of the camera. So what we need to do is zero out any very small values. Because this game controller isn't a perfect input device. It doesn't always calibrate to precisely 20 So what we need to do is set a dead zone where we have any values that are, let's say, less than 0.5 will be considered zero. So I'm gonna go over to the project settings input and locate the Stick X and stick y on. I'll put a very small value in here for the Dead Zone, and so it's a 0.5 and do the same thing over here 0.5 So any number that's less than that will be rounded off to zero. I'll close the project settings window and let's play the game again. And now when I move the camera around, it just comes to rest pretty quickly, and you want to make sure that's true by testing it a few times and having it just come to rest immediately when you let go of it. I think in my case, I'm getting some mixed results. So what I might want to do is just boost up the value a little higher for the dead zone. I'm gonna go all the way up 2.1 so we can consider any value less than that to be zero, and now I'll test the game again. And when I released them right analog stick. It always stops now because all those little values are rounded off zero, so that behaviour is much better now. The next thing I'd like to address is how fast the camera moves. I could move way too fast. So in the Y Axis is, which is what we're looking at here, I'd like to slow that down. So I'm going to get out of play mode and come over here and locate the Y Axis speed, which is set to by default. So let's make that, let's say, 0.5 and see how that plays out. I'll play the game again, and then now when I move the axis up and down, it's at a much more reasonable pace. And the Sina machine free look camera has this saved during play setting. So any changes that I make in here should stick after I get out of play mode. So that will enable me to just these numbers and see how I like it kind of Inter Actively. I'll set this at 100 so that I can't move the X axis around so quickly and that works pretty well. So now I'm going to run around in the game and just see how this looks so I can move around in the game and I can also use the right analog stick to control the position of the camera . And so this is looking a lot better. I have much more control over exactly where I want to be in space, looking at my character and moving around. I have much more control than I ever did with the keyboard. But now, to make the game interesting, of course, I have to turn on the NPC and play test the game. Once everything is tuned the way that you like it, you can go ahead and build the game and make it a stand alone game that you can play. Even if you don't have a copy of unity, we'll do that in the next video. 72. Building and playing standalone game: At this point, we're ready to build our first game. So let's go up to the file menu and save the scene. If it's not saved already and then go to file build settings and here we need to add the scenes into the build by clicking the add open scenes button. You can also drag and drop scenes from the Project window in here. And the idea is, if you're game had multiple scenes or levels, you'd want to bring them all into the build so they would all be compiled into the execute herbal. In my case, I'd like to create a standalone PC game, and so I'm on this item here. If you're on the Mac or Linux, you can do the same. But there are all these other platforms to choose from in here that you can download files for and configure in this course. We're just going to build a stand alone game, though, and so I'll have a choice here on Windows. Whether I want it to be 32 or 64 bit, I'll choose 64 and then before I actually build the game and compile it, I'm going to go to player settings and that opens up the project settings Window on the player tab. And here's where you can put in your company Name the name of the game, the version number, the icons and so on. I'm going to make a change here under resolution and presentation. Open that up and I'd like to change the display resolution dialogue from disabled to enabled. And this is actually now considered a deprecate ID feature that will ultimately be removed . But I like it for the time being because it gives the user a chance to set their resolution and learn about the way that the game controls air mapped. But that is something that you could build on your own with your own user interface, which would probably be a good idea in the end. But for now, this is a quick and easy way to bring this functionality into the game. I'd also like to change the supported aspect ratios and disable anything that isn't 16 by nine. And now I think I'm ready to build the game so I can close project settings and go ahead and build, and it's going to prompt me for a folder to place these assets in. So I'm going to right click in here and create a new folder for this purpose called Build. And I'll select that folder and it will right away get to work compiling this game and putting all of the different dependencies into this execute herbal. So here's that output and we have the e X e filing right here, and I'll this double click on that to launch it. It should begin by opening up this configuration dialog that I said was deprecate ID, and that gives us a chance to set the screen resolution. Notice that all of these air 16 by nine I'm gonna have it be windowed, and I'll set the graphics quality at ultra and over on the input tab. You can learn about the mapping of the various input to the different features in the game . So we have, For example, we have stick X and stick. Why are set to specific axes on the Xbox one controller? So here's where you can learn about that. But this really wouldn't be appropriate for the user of a polished game to see so I can understand whether deprecating this dialog box, I'll go ahead and play the game and I need to start running right away. To get away from the robot from the performance is really good. I'm happy with it. I can Crouch and Aiken jump and I can run around and try to evade that robot here. Oh, he's coming for me. Oh, and I lost. So it says defeat in the lower left hand corner and it says, Restart in the upper right And those labels air pretty small, so I might want to go back into the U I and make them larger. That's something I could only really learn by play testing the game like I'm doing now in the finished product in Click Restart Appear and try again and have fun with it. So congratulations on going all the way from first principles of creating a character and bringing in here and finally building a game. So congratulations, job well done. 73. Next steps: Hi, Scott. On start here, I wanted to say thank you very much for taking this course. I really hope that you learned a lot and that you had fun in the process. I look forward to seeing the kinds of games and simulations that you're able to create with this knowledge now that you can create third person players in a I Driven N PCs using a wide variety of different humanoids that you bring into unity. I also would like to offer you a 10% off coupon for any of the courses that I host at scott dot training. And I wanted to point out that the next course on Unity that I have coming up will be called the Rial Time Building simulator. And the idea of this course is that I've put a lot of energy into coding all the different possibilities that you might want in a building simulation. And you can implement all of these different cool features in your simulation without knowing how to code it all. You can just use out of the box what I've created, so I hope that you check that out and thanks again