0:00:02.330,0:00:04.168 In this video we're going to setup our 0:00:04.168,0:00:06.168 player animator controller so that 0:00:06.168,0:00:08.168 we can control what animation 0:00:08.168,0:00:11.170 is playing via a script. 0:00:11.170,0:00:13.170 The first thing that we're going to do is to add 0:00:13.170,0:00:15.738 the player prefab back to the hierarchy. 0:00:16.224,0:00:18.224 Let's go to Prefabs 0:00:20.013,0:00:23.762 select the player and drag to the hierarchy. 0:00:25.066,0:00:29.507 Next we're going to open our player animator controller. 0:00:29.507,0:00:31.507 Let's go to Animations 0:00:32.991,0:00:34.991 Animator Controllers 0:00:35.920,0:00:37.920 and double click Player. 0:00:39.279,0:00:41.680 Here we have the animations that we created 0:00:41.680,0:00:43.984 earlier which have been added to the animator 0:00:43.984,0:00:45.832 controller has states. 0:00:45.832,0:00:47.832 Let's lay these out so that we can see them a little more 0:00:47.832,0:00:49.832 clearly and we'll move the PlayerIdle up, 0:00:50.817,0:00:52.817 the PlayerChop will be over here and 0:00:52.817,0:00:54.817 the PlayerHit will be over here. 0:00:55.122,0:00:59.096 The PlayerIdle is orange because it's the default state. 0:00:59.096,0:01:01.096 So when the game starts playing 0:01:01.096,0:01:03.876 the player's idle animation is going to play. 0:01:03.876,0:01:05.876 What we're going to do is setup the transitions 0:01:05.876,0:01:08.901 when the PlayerIdle animation will stop playing and will 0:01:08.901,0:01:10.901 transition to either the Chop animation, 0:01:10.901,0:01:12.901 when the player attacks a wall, 0:01:12.901,0:01:14.901 or to the Hit animation when the player 0:01:14.901,0:01:16.901 is attacked by an enemy. 0:01:17.178,0:01:19.178 The first thing that we're going to want to do is setup 0:01:19.178,0:01:21.178 some parameters which are going to 0:01:21.178,0:01:23.178 be what we're going to use to trigger 0:01:23.178,0:01:26.089 those animations from our scripts. 0:01:26.380,0:01:28.380 You may need to click the Parameters button to 0:01:28.380,0:01:30.057 make the parameters visible, 0:01:30.057,0:01:32.280 and then we'll hit the + button 0:01:32.280,0:01:35.181 and add a parameter of the type trigger. 0:01:35.874,0:01:38.272 This first one is going to be called playerChop. 0:01:38.682,0:01:42.081 A trigger is like a boolean except it will 0:01:42.081,0:01:45.894 immediately be reset after it's used in a transition. 0:01:45.894,0:01:48.496 So it's a boolean that's going to remain true 0:01:48.496,0:01:50.496 for the frame in which it's called 0:01:50.496,0:01:52.496 and then become false again. 0:01:53.371,0:01:56.095 We're going to create another one called playerHit. 0:01:56.396,0:01:59.445 Next we want to create some transitions between our states. 0:01:59.445,0:02:01.211 Let's right click PlayerIdle, 0:02:01.746,0:02:03.746 select Make Transition, 0:02:04.088,0:02:07.002 and drag to our PlayerChop state. 0:02:08.410,0:02:11.135 We're then going to right click on PlayerChop 0:02:11.135,0:02:13.135 and make a transition back from 0:02:13.135,0:02:16.044 PlayerChop to PlayerIdle. 0:02:16.044,0:02:18.044 This means that PlayerIdle can transition 0:02:18.044,0:02:20.775 to PlayerChop and PlayerChop 0:02:20.775,0:02:24.026 can then transition back to PlayerIdle. 0:02:24.026,0:02:26.423 We'll click on the transition from PlayerIdle to 0:02:26.423,0:02:29.095 PlayerChop to make it visible in the inspector. 0:02:29.492,0:02:33.405 The transition from PlayerIdle to PlayerChop 0:02:33.405,0:02:36.404 is not going to have an exit time. 0:02:36.404,0:02:38.889 We're going to uncheck Has Exit Time. 0:02:38.889,0:02:41.399 What this means is that we're not going to wait 0:02:41.399,0:02:43.399 for the PlayerIdle animation to finish 0:02:43.399,0:02:47.286 or to reach any certain point before we can 0:02:47.286,0:02:48.809 transition to PlayerChop. 0:02:48.809,0:02:50.809 We're going to want the transition to happen 0:02:50.809,0:02:54.609 abruptly from PlayerIdle to PlayerChop 0:02:54.609,0:02:58.021 regardless of where we are in the Idle animation. 0:02:58.021,0:03:00.021 We're also going to open the settings and 0:03:00.021,0:03:03.203 set the transition duration to 0. 0:03:03.654,0:03:05.654 We're going to use a transition duration of 0 0:03:05.654,0:03:08.901 when we're working with sprite-based animation. 0:03:08.901,0:03:10.901 When we're working with 3D animation 0:03:10.901,0:03:12.901 it's common that we may want to blend 0:03:12.901,0:03:15.064 between animation states 0:03:15.064,0:03:17.977 but with sprite-based animation that's not possible 0:03:17.977,0:03:20.333 so we're going to want to immediately transition 0:03:20.333,0:03:22.333 from one state to another. 0:03:23.140,0:03:25.140 Next we're going to determine what is going 0:03:25.140,0:03:27.140 to cause this transition to happen. 0:03:27.140,0:03:29.140 In our list of conditions here we're going to click 0:03:29.140,0:03:31.978 the + button to add a new condition 0:03:31.978,0:03:33.978 which will determine when the transition 0:03:33.978,0:03:35.978 will be made. 0:03:37.496,0:03:40.385 A list of conditions will appear here, 0:03:40.385,0:03:42.385 in this case PlayerChop, which is the 0:03:42.385,0:03:44.761 default is actually the condition that we want. 0:03:44.761,0:03:47.601 If we wanted to change it we could choose from the list 0:03:47.601,0:03:50.502 and choose either PlayerChop or PlayerHit. 0:03:50.502,0:03:52.502 Now when the PlayerChop trigger is 0:03:52.502,0:03:54.502 set from our player script we'll 0:03:54.502,0:03:57.961 transition from PlayerIdle to PlayerChop. 0:03:58.813,0:04:01.646 For our transition from PlayerChop 0:04:01.646,0:04:05.704 back to PlayerIdle here we're going to keep 0:04:05.704,0:04:07.704 Has Exit Time active but we're going 0:04:07.704,0:04:10.610 to set it to 1, meaning that the PlayerChop 0:04:10.610,0:04:12.610 animation is going to need to be completely 0:04:12.610,0:04:15.369 finished before we're going to transition 0:04:15.369,0:04:17.202 back to PlayerIdle. 0:04:17.202,0:04:20.916 We're also going to set the transition duration here to 0. 0:04:22.358,0:04:24.358 Because we set Has Exit Time 0:04:24.358,0:04:26.358 to true from PlayerChop 0:04:26.358,0:04:28.358 to PlayerIdle we're not going to 0:04:28.358,0:04:30.358 need any additional conditions, 0:04:30.358,0:04:32.358 the transition will be made 0:04:32.358,0:04:34.358 when the exit time is reached. 0:04:34.594,0:04:37.367 Let's setup the same things for PlayerHit. 0:04:38.726,0:04:40.361 We'll select PlayerIdle, 0:04:40.948,0:04:42.948 choose Make Transition, 0:04:42.948,0:04:44.948 and drag to PlayerHit. 0:04:46.460,0:04:49.319 We'll click on PlayerHit, right click, 0:04:49.319,0:04:51.319 choose Make Transition, 0:04:52.526,0:04:55.313 and transition back to PlayerIdle. 0:04:57.352,0:04:59.918 We'll highlight the transition from PlayerIdle 0:04:59.918,0:05:02.835 to PlayerHit, and here we're going to set 0:05:02.835,0:05:05.364 Has Exit Time to false 0:05:05.364,0:05:07.364 because we want to interrupt the 0:05:07.364,0:05:10.960 PlayerIdle animation whenever the player is hit. 0:05:10.960,0:05:14.524 And we're going to set our transition duration again to 0. 0:05:16.022,0:05:19.002 In our list of conditions we're going to hit the + button, 0:05:20.528,0:05:24.234 and select PlayerHit from the drop down. 0:05:24.959,0:05:27.928 For our transition back to PlayerIdle. 0:05:28.927,0:05:30.927 We're going to use Has Exit Time because 0:05:30.927,0:05:33.219 we want the animation to finish playing 0:05:33.219,0:05:35.637 setting Exit Time to 1 because we want it to 0:05:35.637,0:05:38.185 transition at the end of the animation, 0:05:38.185,0:05:41.098 and we're going to set the transition duration to 0. 0:05:41.916,0:05:44.753 Before we move on we're going to give this a quick test. 0:05:44.753,0:05:47.257 Let's temporarily dock the animator window 0:05:47.257,0:05:49.257 down here on the bottom of the screen. 0:05:50.367,0:05:52.367 Play our game, and what we'll do 0:05:52.367,0:05:54.367 is we're going to manually fire the 0:05:54.367,0:05:56.367 triggers and see what happens. 0:05:57.033,0:05:59.033 First we'll try PlayerChop. 0:05:59.851,0:06:01.851 And then we'll try PlayerHit. 0:06:03.446,0:06:05.446 Excellent, so we can see that those are working. 0:06:06.181,0:06:09.237 Now that we've got our player animator controller working 0:06:09.237,0:06:11.237 we're going to move on in the next video 0:06:11.237,0:06:13.237 to writing the player script.