Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
1
00:00:00,000 --> 00:00:03,888
[MUSIC]
2
2
00:00:03,888 --> 00:00:07,269
In this video, we're gonna create
the two extra states of running and
3
3
00:00:07,269 --> 00:00:09,470
climbing to go along
with our idling state.
4
4
00:00:09,470 --> 00:00:11,890
And I'll introduce you to transitions.
5
5
00:00:11,890 --> 00:00:15,860
We'll make some parameters so that we
can transition from one state to another
6
6
00:00:15,860 --> 00:00:20,420
simply by clicking the checkbox here to
show now my character is climbing, and
7
7
00:00:20,420 --> 00:00:22,290
now my character is running.
8
8
00:00:22,290 --> 00:00:23,750
Let's jump in and get started.
9
9
00:00:23,750 --> 00:00:27,650
Okay, let's navigate our way to
the sprite sheet for the character.
10
10
00:00:27,650 --> 00:00:28,470
We can see it there.
11
11
00:00:28,470 --> 00:00:30,890
We've got a bunch of
sprites to choose from.
12
12
00:00:30,890 --> 00:00:34,538
What we're going to start off
with is running, I think.
13
13
00:00:34,538 --> 00:00:36,066
So we're gonna scroll down and
look for the running.
14
14
00:00:36,066 --> 00:00:39,123
I'm just gonna go and
open up the sprite sheet itself so
15
15
00:00:39,123 --> 00:00:40,856
I can see where that goes from.
16
16
00:00:40,856 --> 00:00:45,250
If I look in there, it's this bottom
one here that's the run animation.
17
17
00:00:45,250 --> 00:00:49,551
So it'd be the very last frame
starting from 19 and going until 28.
18
18
00:00:49,551 --> 00:00:52,478
So that's gonna be our run.
19
19
00:00:52,478 --> 00:00:53,960
Don't worry about doing that.
20
20
00:00:53,960 --> 00:00:56,900
Okay, so let's go find 19 in our
sprite sheet here, 15, 16, 17, 18, 19.
21
21
00:00:56,900 --> 00:01:01,888
As we did before, we're gonna
highlight everything all the way down
22
22
00:01:01,888 --> 00:01:06,712
to the final one down here,
right-click, Create > Animation.
23
23
00:01:09,423 --> 00:01:13,450
We'll call this Running, wonderful.
24
24
00:01:13,450 --> 00:01:15,570
Now from here, we can, as we did before,
25
25
00:01:15,570 --> 00:01:19,320
drag that into our Animator,
Animator Controller.
26
26
00:01:19,320 --> 00:01:23,170
We have this state of Running that at the
moment consists of our running animation
27
27
00:01:23,170 --> 00:01:24,082
and not much else.
28
28
00:01:24,082 --> 00:01:28,410
While we're here, let's click on
Running and make sure we loop that and
29
29
00:01:28,410 --> 00:01:31,460
drag Running into the Animations folder.
30
30
00:01:31,460 --> 00:01:32,799
So now we have Running and Idle.
31
31
00:01:32,799 --> 00:01:36,750
As a piece of consistency,
I'm gonna rename Idle to Idling.
32
32
00:01:36,750 --> 00:01:38,922
It's not really a word, but
33
33
00:01:38,922 --> 00:01:43,225
I wanna have my states very clearly be the
thing that you are doing at the moment.
34
34
00:01:43,225 --> 00:01:45,320
You're running at the moment,
you're climbing at the moment,
35
35
00:01:45,320 --> 00:01:46,680
you're idling at the moment.
36
36
00:01:46,680 --> 00:01:48,430
So that's super duper clear on that.
37
37
00:01:48,430 --> 00:01:50,910
Okay, now we have our Running state.
38
38
00:01:50,910 --> 00:01:54,130
We need to make a transition
from Idling to Running so
39
39
00:01:54,130 --> 00:01:56,650
that we can say what needs to happen for
40
40
00:01:56,650 --> 00:02:00,240
the player to stop being in an idling
state and start being in a running state.
41
41
00:02:00,240 --> 00:02:04,830
To make a transition, right-click on
the state, click on Make Transition and
42
42
00:02:04,830 --> 00:02:07,530
then you'll have this arrow
that you can point elsewhere.
43
43
00:02:07,530 --> 00:02:10,267
We'll point over the Running and
left-click on there.
44
44
00:02:10,267 --> 00:02:12,800
So now I have a state transition
leading into Running.
45
45
00:02:12,800 --> 00:02:14,700
If you click on the arrow itself or
46
46
00:02:14,700 --> 00:02:18,505
the line itself, let me show you
what's going on with that transition.
47
47
00:02:18,505 --> 00:02:20,255
There's a couple of things
in here to have a look at.
48
48
00:02:20,255 --> 00:02:23,355
First of all,
we've got a little bit of blending that
49
49
00:02:23,355 --> 00:02:25,805
Unity is trying to do from
one state to another.
50
50
00:02:25,805 --> 00:02:28,735
Now that ends up looking a little
bit crumby because we've got nice,
51
51
00:02:28,735 --> 00:02:30,645
clean 2D animation here.
52
52
00:02:30,645 --> 00:02:33,907
We don't need it to blend as
we might do with 3D animation.
53
53
00:02:33,907 --> 00:02:37,551
So I'm going to open up Settings and
54
54
00:02:37,551 --> 00:02:43,760
just turn Exit Time to 0 and
the Fixed Duration to 0 as well.
55
55
00:02:43,760 --> 00:02:45,998
Now there won't be any of that
blending that needs to take place.
56
56
00:02:45,998 --> 00:02:49,160
So we can probably just do
the transition duration if we wanna be
57
57
00:02:49,160 --> 00:02:50,980
a little bit quicker about it.
58
58
00:02:50,980 --> 00:02:52,355
So we've put that to 0.
59
59
00:02:52,355 --> 00:02:54,535
Now we have this movement into Running.
60
60
00:02:54,535 --> 00:02:59,525
We need to say what condition is going to
be met for this trigger to take place.
61
61
00:02:59,525 --> 00:03:01,929
So in our Animator window,
make sure Parameters is clicked.
62
62
00:03:01,929 --> 00:03:06,281
We're gonna click the + icon just here,
and we've got a choice of Float, Int,
63
63
00:03:06,281 --> 00:03:07,433
Bool, and Trigger.
64
64
00:03:07,433 --> 00:03:11,399
For now we're going to set up a Bool,
and this Bool we will call Running.
65
65
00:03:12,820 --> 00:03:15,906
We come back over onto our Conditions.
66
66
00:03:15,906 --> 00:03:19,495
Make sure you have your transition
selected here, click +.
67
67
00:03:19,495 --> 00:03:21,969
And the only condition we've
got at the moment is Running.
68
68
00:03:21,969 --> 00:03:23,761
That's the only one
we've set up over here.
69
69
00:03:23,761 --> 00:03:25,616
And Running is true.
70
70
00:03:25,616 --> 00:03:29,137
So basically, it's saying when
the Bool of Running is true,
71
71
00:03:29,137 --> 00:03:32,350
then we transition into
the state of Running.
72
72
00:03:32,350 --> 00:03:33,470
That's pretty straightforward.
73
73
00:03:33,470 --> 00:03:35,087
If we click on Running, right-click,
74
74
00:03:35,087 --> 00:03:38,800
Make Transition,
we can transition back to Idling.
75
75
00:03:38,800 --> 00:03:39,726
And a micro challenge for you.
76
76
00:03:39,726 --> 00:03:44,390
What's the condition where we will
transition from Running back to Idling?
77
77
00:03:44,390 --> 00:03:50,180
That would be + Running is false,
of course.
78
78
00:03:50,180 --> 00:03:54,650
Same as before,
I'm gonna make the Transition Duration 0
79
79
00:03:54,650 --> 00:03:56,940
just to make sure we don't
have any of that overlap here.
80
80
00:03:56,940 --> 00:04:00,257
I'll put this to 0 as well, okay, just so
it's nice and clear this is gonna happen.
81
81
00:04:00,257 --> 00:04:04,520
I just click straight into that
other state without any blend.
82
82
00:04:04,520 --> 00:04:06,620
Okay, so now we've got that flow going on.
83
83
00:04:06,620 --> 00:04:11,080
This is all hooked up to the player still
cuz the player has the Animator Controller
84
84
00:04:11,080 --> 00:04:14,270
in here called Player, so
it knows this straight away.
85
85
00:04:14,270 --> 00:04:19,530
If we click on Play, you should see
the player sitting there idling.
86
86
00:04:19,530 --> 00:04:22,140
I'll just go back to my Scene view so
I can get in nice and close.
87
87
00:04:22,140 --> 00:04:23,690
The player's sitting there idling.
88
88
00:04:23,690 --> 00:04:27,350
If we click on this, this is to simulate
if we were to call it in code and
89
89
00:04:27,350 --> 00:04:30,360
say, turn the Bool to true.
90
90
00:04:30,360 --> 00:04:32,260
Now the player's running,
run, run, run, run, run.
91
91
00:04:32,260 --> 00:04:34,150
And then if we click on it to simulate,
92
92
00:04:34,150 --> 00:04:38,200
now code's saying turn the Bool to false,
then back to animation again.
93
93
00:04:38,200 --> 00:04:43,020
So we've got this nice flow from
state to state, very excellent.
94
94
00:04:43,020 --> 00:04:47,390
Now the next state we're going to set
up is going to be the climb ladder.
95
95
00:04:47,390 --> 00:04:49,820
That's the other main state
we'll have in our game.
96
96
00:04:49,820 --> 00:04:53,060
Let's just go have a look at our sprite
sheet to see which one that would be.
97
97
00:04:53,060 --> 00:04:56,737
Climb ladder is pretty much
just gonna be these two here.
98
98
00:04:56,737 --> 00:05:00,700
So 14 and 15,
I've got those in my sprites here.
99
99
00:05:00,700 --> 00:05:04,040
So what I want you to do as
a challenge is to implement climb and
100
100
00:05:04,040 --> 00:05:07,880
run animation states,
create the transitions from idle, and
101
101
00:05:07,880 --> 00:05:10,610
create the triggers for
each of the states.
102
102
00:05:10,610 --> 00:05:13,060
So go ahead and do that for
climb and run, and
103
103
00:05:13,060 --> 00:05:15,010
I'll see you back here
when you've got that done.
104
104
00:05:16,770 --> 00:05:19,362
Okay, so it was 14 and 15, I believe.
105
105
00:05:19,362 --> 00:05:20,278
Let's find those.
106
106
00:05:20,278 --> 00:05:25,357
There's 14 and 15 [SOUND] excellent,
looks like a wonderful ladder climbing.
107
107
00:05:25,357 --> 00:05:30,080
Right-click, Create > Animation,
if I can find it, there it is, Animation.
108
108
00:05:30,080 --> 00:05:33,660
This will be Climbing animation.
109
109
00:05:33,660 --> 00:05:37,368
Drag that into our state machine in here.
110
110
00:05:37,368 --> 00:05:41,150
From Idling, right-click,
Make Transition into Climbing.
111
111
00:05:41,150 --> 00:05:44,510
And I'll do the other one straight away,
Make Transition back to Idling.
112
112
00:05:44,510 --> 00:05:47,597
Click on this first one and
just tidy up little of this.
113
113
00:05:47,597 --> 00:05:51,232
You don't have to tidy up the blending,
but as I've mentioned,
114
114
00:05:51,232 --> 00:05:53,700
I like to do this, dot dot dah, wonderful.
115
115
00:05:53,700 --> 00:05:56,890
Click on the + button and create
another Bool, which will be Climbing.
116
116
00:05:58,330 --> 00:06:00,140
Climbing is our parameter.
117
117
00:06:00,140 --> 00:06:01,040
Then over on here,
118
118
00:06:01,040 --> 00:06:06,270
our condition going from Idling to
Climbing should be Climbing is true.
119
119
00:06:06,270 --> 00:06:09,340
And then if we click on
the other direction,
120
120
00:06:09,340 --> 00:06:15,130
the condition of Climbing should be false.
121
121
00:06:15,130 --> 00:06:17,393
And again, just tidy this up.
122
122
00:06:17,393 --> 00:06:21,820
Okay, and you can see in here, we've got
something that's called Has Exit Time.
123
123
00:06:21,820 --> 00:06:23,145
Basically, this is saying,
124
124
00:06:23,145 --> 00:06:25,908
you've got a number of ways of
exiting this animation state.
125
125
00:06:25,908 --> 00:06:29,692
One way is if you want
the animation to play.
126
126
00:06:29,692 --> 00:06:31,830
And then as soon as
the animation finishes playing,
127
127
00:06:31,830 --> 00:06:36,670
go back or transition back to the state.
128
128
00:06:36,670 --> 00:06:37,799
Then you can use Exit Time.
129
129
00:06:37,799 --> 00:06:40,210
So it said there's ten
frames of animation.
130
130
00:06:40,210 --> 00:06:41,276
You do those ten frames.
131
131
00:06:41,276 --> 00:06:42,720
If Has Exit Time is on,
132
132
00:06:42,720 --> 00:06:46,340
after the ten frames,
it can return back to the other state.
133
133
00:06:46,340 --> 00:06:50,300
So I wanna click Has Exit Time off cuz
what we're using here is the condition of
134
134
00:06:50,300 --> 00:06:52,970
the Bool to say when
the transition takes place.
135
135
00:06:52,970 --> 00:06:56,470
Have a look over here,
turn off Has Exit Time there, and
136
136
00:06:56,470 --> 00:07:00,130
same with all these other ones,
just turning off Has Exit Time.
137
137
00:07:00,130 --> 00:07:05,170
We only want that in a situation where we
definitely end after we play a particular
138
138
00:07:05,170 --> 00:07:07,250
single shot animation.
139
139
00:07:07,250 --> 00:07:10,303
Now let's click Play,
see if we've hooked all this up correctly.
140
140
00:07:10,303 --> 00:07:13,600
The character should
be defaulting to Idle.
141
141
00:07:13,600 --> 00:07:15,390
And you can see the Idle
clicking through here.
142
142
00:07:15,390 --> 00:07:16,240
This is the state we're in.
143
143
00:07:16,240 --> 00:07:17,405
It's playing through the frames.
144
144
00:07:17,405 --> 00:07:20,120
We click on Running, yes, it runs.
145
145
00:07:20,120 --> 00:07:22,190
And Climbing, no,
it's not climbing at the moment.
146
146
00:07:22,190 --> 00:07:23,260
What have we done wrong here?
147
147
00:07:23,260 --> 00:07:25,320
Let's have a look at our transitions.
148
148
00:07:25,320 --> 00:07:27,010
We have Running is true.
149
149
00:07:27,010 --> 00:07:30,390
You're probably yelling at the screen,
saying, Rick, you put in Running.
150
150
00:07:30,390 --> 00:07:32,020
You should've put in Climbing.
151
151
00:07:32,020 --> 00:07:33,390
There we go, we've found it.
152
152
00:07:33,390 --> 00:07:34,460
Let's click Play here.
153
153
00:07:35,640 --> 00:07:36,860
Thank you for yelling at the screen,
154
154
00:07:36,860 --> 00:07:40,030
if you did yell at the screen
in that instance, Climbing, yep.
155
155
00:07:40,030 --> 00:07:45,240
And it's stuck, which says that we
are not looping, if I am correct.
156
156
00:07:45,240 --> 00:07:47,650
We haven't clicked on
looping time in there.
157
157
00:07:47,650 --> 00:07:50,220
That stays in play mode,
which is all good.
158
158
00:07:50,220 --> 00:07:55,180
Now that we've got it, our character
can run and our character can climb.
159
159
00:07:55,180 --> 00:07:56,910
So these are all the states
that we need for now.
160
160
00:07:56,910 --> 00:08:00,790
As our game gets more complex, we might
wish to add in rolling or shooting or
161
161
00:08:00,790 --> 00:08:01,570
jumping.
162
162
00:08:01,570 --> 00:08:02,116
But for now,
163
163
00:08:02,116 --> 00:08:05,710
all we need functionality-wise is the
player can run and the player can climb.
164
164
00:08:05,710 --> 00:08:08,158
And after we put all of that
gameplay functionality in,
165
165
00:08:08,158 --> 00:08:11,246
we might revisit our states in here and
our animations and add more in.
166
166
00:08:11,246 --> 00:08:15,667
But we don't want to overinvest in this
until we've got our core gameplay created
167
167
00:08:15,667 --> 00:08:18,500
and we know how it all fits together and
how it looks.
168
168
00:08:18,500 --> 00:08:20,930
So great work in this video, and
I'll see you in the next video.
16552
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.