1 00:00:04,100 --> 00:00:04,790 ‫In this video. 2 00:00:04,790 --> 00:00:07,940 ‫We're going to take care of the animation of our character. 3 00:00:07,940 --> 00:00:11,060 ‫And so let's go ahead and create a character. 4 00:00:11,060 --> 00:00:17,060 ‫So let's go to assets and create a new folder and let's call that one character. 5 00:00:17,630 --> 00:00:24,740 ‫And within that folder, I want to drag my character into it because in here we'll be the character 6 00:00:24,740 --> 00:00:31,280 ‫and the character animation as this character prefab is a different one than the one that we had from 7 00:00:31,280 --> 00:00:34,400 ‫the asset store because we have changed some things already. 8 00:00:34,400 --> 00:00:41,630 ‫We, for example, deleted the controller, the animation animation controller, we created a new script 9 00:00:41,630 --> 00:00:42,530 ‫and so forth. 10 00:00:42,710 --> 00:00:49,010 ‫So now let's go into the character folder and create a new animation controller, because whenever you 11 00:00:49,010 --> 00:00:53,900 ‫want to animate an object, then you need to have an animation controller. 12 00:00:53,900 --> 00:00:58,190 ‫And I'm just going to call that one char anim controller. 13 00:00:59,090 --> 00:01:04,310 ‫So char underscore anim underscore controller. 14 00:01:05,930 --> 00:01:11,090 ‫You could choose a name that you prefer, but char anim controller is pretty precise of what this does. 15 00:01:11,090 --> 00:01:15,200 ‫So now let's open that up and I want the animator control to be full screen. 16 00:01:15,200 --> 00:01:19,370 ‫So I'm going to drag game into that and I'm going to go to animator. 17 00:01:20,300 --> 00:01:20,600 ‫All right. 18 00:01:20,600 --> 00:01:23,240 ‫So we have here several states already. 19 00:01:23,240 --> 00:01:24,200 ‫We have the nanny state. 20 00:01:24,200 --> 00:01:26,810 ‫We have an entry point and we have an exit point. 21 00:01:26,810 --> 00:01:32,660 ‫And those are the ones that are automatically created whenever you create an anim controller. 22 00:01:32,870 --> 00:01:35,750 ‫So the one that we need now is a new state. 23 00:01:35,750 --> 00:01:42,650 ‫So we can create a new state any time by right clicking into this field and then creating a state. 24 00:01:42,650 --> 00:01:44,900 ‫And we're going to create an empty state. 25 00:01:44,900 --> 00:01:51,290 ‫As you can see, there is already a transition created for us from entry to new state. 26 00:01:51,290 --> 00:01:58,640 ‫Entry is the point whenever our animator awakes, which means whenever our player awakes, that's when 27 00:01:58,640 --> 00:02:00,290 ‫the entry point is. 28 00:02:00,290 --> 00:02:04,310 ‫And then it goes directly via transition to any state. 29 00:02:04,580 --> 00:02:09,860 ‫Now if we click on any state, we should change the name because the animation or the state that we 30 00:02:09,860 --> 00:02:14,750 ‫want to have is run, which means we want the player to have a run animation. 31 00:02:14,840 --> 00:02:21,350 ‫And the beauty is that the motion that we need for that, so the actual graphical animation is already 32 00:02:21,350 --> 00:02:21,890 ‫there. 33 00:02:21,950 --> 00:02:25,100 ‫It's this animation clip called Run. 34 00:02:25,220 --> 00:02:28,100 ‫You could have walk jump down all of those. 35 00:02:28,100 --> 00:02:32,300 ‫These are the ones that we have within our asset that we have downloaded. 36 00:02:33,100 --> 00:02:34,960 ‫But the one that we want to use is run. 37 00:02:34,960 --> 00:02:41,620 ‫So let's simply start that motion and now let's open up, run so we can have a better look at what this 38 00:02:41,620 --> 00:02:42,130 ‫does. 39 00:02:42,130 --> 00:02:47,380 ‫So double click on run here in the motion on the right hand side and you will find it here under common 40 00:02:47,380 --> 00:02:52,930 ‫people and animations for our Super Saiyan character free pack, free sample. 41 00:02:52,930 --> 00:02:54,190 ‫So let's have a look at run. 42 00:02:54,190 --> 00:02:57,160 ‫Let's edit it and what we can see here. 43 00:02:57,160 --> 00:03:03,520 ‫There are several informations and what is important for us is the loop time because that one is activated. 44 00:03:03,520 --> 00:03:11,560 ‫That means that our player will constantly have an animation that will repeat this piece here multiple 45 00:03:11,560 --> 00:03:17,590 ‫times, and the length is 0.667, which is 0.66 7 seconds. 46 00:03:17,590 --> 00:03:24,730 ‫So after a two thirds of a second, this animation will be done and it will repeat itself as soon as 47 00:03:24,730 --> 00:03:27,130 ‫loop time or if loop time is activated. 48 00:03:27,580 --> 00:03:31,180 ‫So let's deactivate loop time and let's have a look at our game. 49 00:03:31,180 --> 00:03:32,290 ‫So let's run it. 50 00:03:32,320 --> 00:03:35,050 ‫So now let's test this with our character. 51 00:03:35,050 --> 00:03:45,040 ‫So let's go to our character and let's drag the chart and controller that we have created into the animator. 52 00:03:45,580 --> 00:03:51,550 ‫So that's our controller that we have created here, and it will go from entry directly to run. 53 00:03:51,550 --> 00:03:54,550 ‫So let's have a look at how this looks like. 54 00:03:56,110 --> 00:04:02,230 ‫And we can see the player runs and runs and runs and even if he falls, he doesn't care. 55 00:04:02,230 --> 00:04:05,620 ‫He's always going to have this run animation, which is not perfect. 56 00:04:05,620 --> 00:04:06,820 ‫We will change that later on. 57 00:04:06,820 --> 00:04:10,600 ‫So as soon as he falls, we want to have a different animation, of course. 58 00:04:10,690 --> 00:04:17,710 ‫So let's go back to our controller and actually I want to go to the run animation again. 59 00:04:17,950 --> 00:04:23,440 ‫So in here the run motion, I want to edit that and I will deactivate loop time now. 60 00:04:23,440 --> 00:04:28,150 ‫So let's go ahead and run the code again or run our game again. 61 00:04:29,650 --> 00:04:32,260 ‫As you can see, loop time is still activated. 62 00:04:35,910 --> 00:04:41,610 ‫So I'm going to apply the loop time to deactivate the loop time and I'm going to start. 63 00:04:41,610 --> 00:04:48,030 ‫And you can see he had one run of this run animation or one repetition, and then afterwards he didn't 64 00:04:48,030 --> 00:04:49,290 ‫run anymore. 65 00:04:49,290 --> 00:04:50,980 ‫So that's what this loop time is for. 66 00:04:51,000 --> 00:04:56,850 ‫It's really important that we leave that activated because what it does, it will repeat this animation 67 00:04:56,850 --> 00:05:01,380 ‫very nicely and our player will run beautifully. 68 00:05:01,380 --> 00:05:03,660 ‫So now deactivated it, of course, again. 69 00:05:03,900 --> 00:05:05,490 ‫So let's run it again. 70 00:05:05,670 --> 00:05:10,590 ‫Let's apply that, by the way, to our run FB X and let's run it again. 71 00:05:13,340 --> 00:05:17,510 ‫Now you'll see he will constantly do this run animation. 72 00:05:18,140 --> 00:05:26,120 ‫So now let's see what happens if we have the game open and at the same time we are here within our run. 73 00:05:26,120 --> 00:05:31,670 ‫By the way, if you want to move that around, you can press your middle button, middle button in your 74 00:05:31,670 --> 00:05:32,240 ‫mouse. 75 00:05:33,230 --> 00:05:36,890 ‫So now let's run our game and see what happens. 76 00:05:37,700 --> 00:05:45,290 ‫And as you can see here, this blue bar at the bottom of our run state is the repetition or the current 77 00:05:45,290 --> 00:05:49,640 ‫position of the animation and or of the motion. 78 00:05:49,640 --> 00:05:57,300 ‫So that's what this two thirds of a second is, pretty much so one run, one repetition of run is two 79 00:05:57,300 --> 00:05:58,580 ‫thirds of a second. 80 00:05:59,210 --> 00:05:59,600 ‫All right. 81 00:05:59,600 --> 00:06:01,770 ‫So now we have the run animation, but that's not it. 82 00:06:01,790 --> 00:06:06,320 ‫We need another animation as well, which is our falling animation. 83 00:06:06,320 --> 00:06:12,590 ‫So whenever our player is falling, we want to have the following animation and we can create a new 84 00:06:12,590 --> 00:06:14,600 ‫state here, create empty. 85 00:06:14,780 --> 00:06:17,330 ‫And that state is going to be called. 86 00:06:19,340 --> 00:06:25,790 ‫Falling and the motion for that is going to be jump down. 87 00:06:26,120 --> 00:06:31,550 ‫So we have the jump float to jump up to pick up and so on and so forth. 88 00:06:31,550 --> 00:06:33,630 ‫And the one we need now is to jump down. 89 00:06:33,650 --> 00:06:38,660 ‫So what it does, it will jump down, actually once again jump down. 90 00:06:38,750 --> 00:06:45,130 ‫So now we need a transition from run to falling because you can consider this as a flow. 91 00:06:45,140 --> 00:06:50,870 ‫So the animation starts at the entry, then it goes to run, and then at one point it will go to falling. 92 00:06:50,870 --> 00:06:55,610 ‫So when ever the player is falling down, we want to fall in animation to run. 93 00:06:55,610 --> 00:07:02,930 ‫So we need a transition, make transition and then we can drag that over to falling and now we can connect 94 00:07:02,930 --> 00:07:03,710 ‫it directly. 95 00:07:03,860 --> 00:07:07,460 ‫So in here you have a transition from run to falling in the inspector. 96 00:07:07,460 --> 00:07:08,840 ‫You can see it straight away. 97 00:07:08,930 --> 00:07:15,080 ‫And what we now need in order to know when this transition should be triggered or should run, so whenever 98 00:07:15,080 --> 00:07:21,260 ‫falling should change, we need to add a condition and in order to add a condition, we can do that 99 00:07:21,260 --> 00:07:21,800 ‫here. 100 00:07:21,800 --> 00:07:23,540 ‫We need to have a parameter. 101 00:07:23,540 --> 00:07:26,270 ‫As you can see, we don't have any parameter yet. 102 00:07:26,270 --> 00:07:28,640 ‫We need to create a new parameter for that. 103 00:07:28,640 --> 00:07:31,610 ‫So on the left hand side, you can see here layers. 104 00:07:31,610 --> 00:07:33,830 ‫And then there is this parameters piece. 105 00:07:33,830 --> 00:07:37,970 ‫So click on parameters on this tab and then on the plus sign. 106 00:07:37,970 --> 00:07:43,130 ‫And now you can choose from four different parameters float, int, bool and trigger. 107 00:07:43,130 --> 00:07:50,150 ‫And in our case we are going to use the trigger because what we want is whenever our player does not 108 00:07:50,150 --> 00:07:56,660 ‫have any physical on the ground anymore, so any physics body under below him, we want this trigger 109 00:07:56,660 --> 00:07:59,510 ‫to be set and we can do that quite quickly. 110 00:07:59,510 --> 00:08:03,530 ‫So let's create this trigger and I'm going to call this trigger is falling. 111 00:08:04,430 --> 00:08:11,840 ‫And now let's click on the transition here on this little arrow or this little line with the arrow and 112 00:08:11,840 --> 00:08:15,020 ‫now we can choose is falling as its condition. 113 00:08:15,290 --> 00:08:20,780 ‫So let's enter that, by the way, if you want to see the is falling animation. 114 00:08:21,700 --> 00:08:24,490 ‫You can see it here, or actually that's the running animation. 115 00:08:24,910 --> 00:08:28,900 ‫So let's see the falling animation, the jump down animation. 116 00:08:31,880 --> 00:08:34,310 ‫You can see this is the jump down animation. 117 00:08:37,760 --> 00:08:42,800 ‫Now we need to set is falling set this trigger somewhere. 118 00:08:42,800 --> 00:08:48,950 ‫And the best position to do that is our code, which means we go back to our script. 119 00:08:48,950 --> 00:08:53,330 ‫So let's go to our character, let's go to char control, character control. 120 00:08:53,330 --> 00:08:57,830 ‫And within the update method, we are going to check if we are still hitting the ground. 121 00:08:58,070 --> 00:09:02,510 ‫And for that we will need a new variable here. 122 00:09:03,870 --> 00:09:05,160 ‫Actually two new variables. 123 00:09:05,160 --> 00:09:06,330 ‫One is public. 124 00:09:06,330 --> 00:09:13,050 ‫So let's create a public one public transform rate start. 125 00:09:14,040 --> 00:09:19,650 ‫Because what we'll do, we'll run array from the bottom of our character and see if we hit any physical 126 00:09:19,650 --> 00:09:21,420 ‫body or if you still hit something. 127 00:09:21,900 --> 00:09:23,850 ‫And if we don't hit it, then we want to trigger. 128 00:09:23,850 --> 00:09:34,920 ‫Of course, then we need an animator, so private animator and so I'm going to call it and within the 129 00:09:34,920 --> 00:09:38,610 ‫update method, I will need a red cast hit. 130 00:09:38,940 --> 00:09:43,230 ‫What that does is it's a structure used to get information back from a red cast. 131 00:09:43,230 --> 00:09:49,110 ‫So it's a red cast that we cast to watch the bottom of our player and then we check is there something 132 00:09:49,110 --> 00:09:49,560 ‫or not? 133 00:09:49,560 --> 00:09:58,200 ‫And I'm going to call it hit and now I can do an if request here or I can add an if condition, if physics 134 00:09:58,410 --> 00:10:08,250 ‫dot recast and in here I give a position, a direction, an out, which is not this one. 135 00:10:08,250 --> 00:10:12,450 ‫So there are several overloads here, plenty. 136 00:10:12,450 --> 00:10:13,560 ‫We're going to use one of them. 137 00:10:13,560 --> 00:10:16,170 ‫So I'm just going to enter the parameters now. 138 00:10:17,220 --> 00:10:27,330 ‫One is Ray Start, which is our transform variable which we created here Ray start dot position. 139 00:10:28,290 --> 00:10:34,080 ‫So that's the origin from the ray where the ray should start then where it goes to. 140 00:10:34,080 --> 00:10:38,520 ‫And I'm just going to use minus transform up, which means it's transformed down. 141 00:10:38,520 --> 00:10:39,840 ‫So go down. 142 00:10:40,350 --> 00:10:46,590 ‫So the direction of the ray, then we check the out, which is simply going to be our hit. 143 00:10:46,590 --> 00:10:55,320 ‫So the ray cast that we have created there and then we need the length of our ray cast and I'm just 144 00:10:55,320 --> 00:10:58,440 ‫going to use math f dot infinity. 145 00:10:58,620 --> 00:11:02,760 ‫So it should go down and down and down whenever that is false. 146 00:11:02,760 --> 00:11:04,890 ‫So that means there is nothing that we hit. 147 00:11:04,890 --> 00:11:07,710 ‫That's why I used this exclamation mark at the beginning. 148 00:11:07,710 --> 00:11:14,400 ‫So I say not physics ray, cast transform, etc. which means if there is no hit towards the bottom, 149 00:11:15,120 --> 00:11:18,060 ‫then please set the trigger of my animation. 150 00:11:18,780 --> 00:11:26,010 ‫So please go ahead and do anim dot set trigger and which trigger. 151 00:11:26,010 --> 00:11:29,160 ‫Well the one is falling that we have just created. 152 00:11:29,310 --> 00:11:34,260 ‫So now of course we need to set our animator because currently we don't do that. 153 00:11:34,260 --> 00:11:37,410 ‫We need to initialize it within our awake method. 154 00:11:37,410 --> 00:11:43,290 ‫So enum is get component and component is called animator. 155 00:11:44,310 --> 00:11:51,180 ‫Now before we test that, we of course need a ray start and restart is a transform component. 156 00:11:51,180 --> 00:11:58,110 ‫So let's go to our character and let's create a new empty object, which I'm just going to call our 157 00:11:58,110 --> 00:11:59,880 ‫Ray start. 158 00:12:00,390 --> 00:12:07,080 ‫And the restart, as you can see here, is at the feet of our player and I want it to be maybe in the 159 00:12:07,080 --> 00:12:08,070 ‫middle of our player. 160 00:12:08,070 --> 00:12:11,610 ‫So just add the stomach or the chest somewhere. 161 00:12:11,700 --> 00:12:17,400 ‫So that means that it's inside of our player and that's where the ray will start and it will go down 162 00:12:17,400 --> 00:12:22,110 ‫and now it will check if there is something at the bottom of him or not. 163 00:12:22,110 --> 00:12:26,180 ‫Is there something so meaning is there a box that we collide with or not? 164 00:12:26,190 --> 00:12:26,700 ‫All right. 165 00:12:26,700 --> 00:12:34,470 ‫So now that we have that, we can assign Ray start to our chart controller and let's drag that in there. 166 00:12:34,470 --> 00:12:37,980 ‫Now we have a transform and now we can check the code. 167 00:12:37,980 --> 00:12:45,750 ‫Let's run that and see if our animator changes, but we can see that it does indeed change. 168 00:12:46,020 --> 00:12:48,300 ‫Maybe that's not the perfect one. 169 00:12:48,480 --> 00:12:50,940 ‫So let's have a look at our animator. 170 00:12:50,940 --> 00:12:53,010 ‫Jump down is the one that I have used. 171 00:12:53,010 --> 00:12:55,680 ‫So let's see if we find a better one. 172 00:12:56,940 --> 00:13:01,320 ‫Let's go ahead and try different one here, different motion. 173 00:13:01,320 --> 00:13:03,180 ‫Let's try jump float. 174 00:13:03,960 --> 00:13:10,680 ‫So let's have a look how that will look like and we can see I think that's much better. 175 00:13:10,680 --> 00:13:12,750 ‫So that's our falling animation. 176 00:13:12,750 --> 00:13:18,180 ‫So that's the animation that will happen whenever the player is falling and dying pretty much. 177 00:13:18,840 --> 00:13:19,500 ‫All right. 178 00:13:19,500 --> 00:13:25,230 ‫So in the next video, we are going to have a look at how to start our game, because now it just starts 179 00:13:25,230 --> 00:13:26,730 ‫whenever we press the run button. 180 00:13:26,730 --> 00:13:28,290 ‫But we need to do it better. 181 00:13:28,320 --> 00:13:30,360 ‫Let's save the scene and see you in the next video.