WEBVTT

1
00:00:06.540 --> 00:00:09.359 A:middle L:90%
So now that we've created our Mecanim character controller.

2
00:00:09.740 --> 00:00:12.130 A:middle L:90%
We want to start copying code in and supplying that

3
00:00:12.130 --> 00:00:14.689 A:middle L:90%
character controller with values. So let's copy in some

4
00:00:14.689 --> 00:00:19.309 A:middle L:90%
values. We're gonna copying these variables here and what

5
00:00:19.309 --> 00:00:21.199 A:middle L:90%
these are is we've got the animator which is a

6
00:00:21.199 --> 00:00:23.870 A:middle L:90%
reference to the character controller. We've got a damping

7
00:00:23.870 --> 00:00:27.019 A:middle L:90%
time which is going to be used to set Uh

8
00:00:27.030 --> 00:00:29.960 A:middle L:90%
sort of a delay on the time that we actually

9
00:00:29.960 --> 00:00:32.859 A:middle L:90%
set this variable direction and the animation controller is

10
00:00:32.859 --> 00:00:36.100 A:middle L:90%
going to be delayed by .25 seconds. And that's

11
00:00:36.100 --> 00:00:37.759 A:middle L:90%
good for if you're doing things like pivoting that you

12
00:00:37.759 --> 00:00:39.659 A:middle L:90%
really want to use the previous rains value on.

13
00:00:40.240 --> 00:00:42.649 A:middle L:90%
And we also are going to have a speed value

14
00:00:42.649 --> 00:00:46.149 A:middle L:90%
and horizontal and vertical that's brought in from the control,

15
00:00:46.159 --> 00:00:49.359 A:middle L:90%
the control stick on their Xbox controller. So

16
00:00:49.359 --> 00:00:51.450 A:middle L:90%
let's copy and the rest of this. We want

17
00:00:51.450 --> 00:00:52.810 A:middle L:90%
to do in our start method. We want to

18
00:00:52.810 --> 00:00:57.090 A:middle L:90%
check if our animator component exists and we want to

19
00:00:57.090 --> 00:00:58.840 A:middle L:90%
grab it if so. So we're gonna do that

20
00:00:58.840 --> 00:01:03.260 A:middle L:90%
here and then we're going to set our animation controller.

21
00:01:04.140 --> 00:01:07.430 A:middle L:90%
So we've got that we've said our animation controller

22
00:01:07.650 --> 00:01:08.599 A:middle L:90%
now we want to supply it with some values.

23
00:01:08.629 --> 00:01:11.859 A:middle L:90%
So an update we're gonna just basically supply it values

24
00:01:11.859 --> 00:01:15.159 A:middle L:90%
for those two floats that we call direction and speed

25
00:01:17.140 --> 00:01:23.370 A:middle L:90%
Get this real fast. And speed, this calculation

26
00:01:23.370 --> 00:01:26.549 A:middle L:90%
here it's basically the same thing is just taking a

27
00:01:26.549 --> 00:01:30.849 A:middle L:90%
new vector too supplying it with the horizontal and vertical.

28
00:01:30.849 --> 00:01:33.379 A:middle L:90%
So making a vector out of that controller and

29
00:01:33.379 --> 00:01:34.290 A:middle L:90%
then describing the square magnitude which is just a little

30
00:01:34.290 --> 00:01:38.980 A:middle L:90%
faster than actually taking the full magnitude. And we

31
00:01:38.980 --> 00:01:40.370 A:middle L:90%
want to do is want to set those floats in

32
00:01:40.370 --> 00:01:42.700 A:middle L:90%
our animation controller. You want to set speed with

33
00:01:42.700 --> 00:01:45.400 A:middle L:90%
the speed value. You want to set direction with

34
00:01:45.400 --> 00:01:47.810 A:middle L:90%
this H value from the controllers. That's basically the

35
00:01:47.810 --> 00:01:51.340 A:middle L:90%
horizontal control stick. And I should probably make this

36
00:01:51.340 --> 00:01:53.859 A:middle L:90%
a lower case D just for good coding practices.

37
00:01:53.640 --> 00:01:56.780 A:middle L:90%
Great. So let's save this and have a look

38
00:01:56.790 --> 00:02:02.370 A:middle L:90%
make sure we didn't break Unity. Great no errors.

39
00:02:02.370 --> 00:02:05.769 A:middle L:90%
That's awesome. So one thing we want to

40
00:02:05.769 --> 00:02:07.090 A:middle L:90%
make sure to is that we understand that this set

41
00:02:07.090 --> 00:02:09.669 A:middle L:90%
float method here all it's doing is taking the speed

42
00:02:09.669 --> 00:02:12.639 A:middle L:90%
value here which is the value in our script.

43
00:02:12.650 --> 00:02:15.889 A:middle L:90%
It's applying it to the animation controller in right here.

44
00:02:15.889 --> 00:02:19.430 A:middle L:90%
So it's just taking values from the script and

45
00:02:19.430 --> 00:02:22.240 A:middle L:90%
putting them into our character controller. And those values

46
00:02:22.240 --> 00:02:24.210 A:middle L:90%
we can use to sort of control these parts of

47
00:02:24.210 --> 00:02:27.659 A:middle L:90%
the state machine. So let's give it a shot

48
00:02:27.659 --> 00:02:30.259 A:middle L:90%
and see if it works to make sure that our

49
00:02:30.639 --> 00:02:32.099 A:middle L:90%
script is on there. We want to make sure

50
00:02:32.099 --> 00:02:35.650 A:middle L:90%
that hopefully this animator component will just be set from

51
00:02:35.759 --> 00:02:38.789 A:middle L:90%
this character controller when we had to start. So

52
00:02:38.789 --> 00:02:39.759 A:middle L:90%
you can see right here the animator just came in

53
00:02:40.139 --> 00:02:42.849 A:middle L:90%
and we see that our direction damp time set.

54
00:02:43.840 --> 00:02:46.180 A:middle L:90%
Now let's try to actually move turn on the

55
00:02:46.180 --> 00:02:49.150 A:middle L:90%
Xbox controller. Oh, we fell over. So

56
00:02:49.150 --> 00:02:52.060 A:middle L:90%
there's a reason for this when we create it looks

57
00:02:52.060 --> 00:02:53.340 A:middle L:90%
like that game Quop. So the reason our characters

58
00:02:53.340 --> 00:02:55.180 A:middle L:90%
flailing on the ground is because you need to actually

59
00:02:55.180 --> 00:02:59.430 A:middle L:90%
set the capsule collider to freeze rotation in all of

60
00:02:59.430 --> 00:03:01.039 A:middle L:90%
the uh X, Y and Z axes. So

61
00:03:01.039 --> 00:03:04.229 A:middle L:90%
basically that's saying that you don't want the character to

62
00:03:04.229 --> 00:03:06.949 A:middle L:90%
fall over and have the rigid body affected by the

63
00:03:06.949 --> 00:03:08.729 A:middle L:90%
root motion of the animation. So we can have

64
00:03:08.729 --> 00:03:10.379 A:middle L:90%
a look at our character, you can see them

65
00:03:10.379 --> 00:03:15.599 A:middle L:90%
running around and as we move the control stick our character

66
00:03:15.599 --> 00:03:16.810 A:middle L:90%
runs backwards and forwards. As you can see we don't

67
00:03:16.810 --> 00:03:19.560 A:middle L:90%
have a camera so this is not so great.

68
00:03:19.939 --> 00:03:21.949 A:middle L:90%
One thing you can do that's gonna make life

69
00:03:21.949 --> 00:03:24.020 A:middle L:90%
a little bit easier is that there's actually a script

70
00:03:24.020 --> 00:03:27.919 A:middle L:90%
that I grabbed off the Unify wiki. And if

71
00:03:27.919 --> 00:03:29.229 A:middle L:90%
you go into the scripts folder, you'll see the

72
00:03:29.229 --> 00:03:30.919 A:middle L:90%
scene view camera follower, so you toss that on

73
00:03:30.919 --> 00:03:35.030 A:middle L:90%
the beta character, we can set this, so

74
00:03:35.030 --> 00:03:36.840 A:middle L:90%
it's only in play mode. What this is going

75
00:03:36.840 --> 00:03:38.740 A:middle L:90%
to do is it's going to create uh this ability

76
00:03:38.740 --> 00:03:40.530 A:middle L:90%
for our scene view to track our character. So

77
00:03:40.530 --> 00:03:43.500 A:middle L:90%
until we have a camera script in our project,

78
00:03:43.500 --> 00:03:45.849 A:middle L:90%
it's going to be pretty, pretty useful. So

79
00:03:45.849 --> 00:03:46.810 A:middle L:90%
we're gonna set the position offset, let's make sure

80
00:03:46.810 --> 00:03:50.099 A:middle L:90%
that actually will turn it off, and now we

81
00:03:50.099 --> 00:03:52.479 A:middle L:90%
can use this to position our character. So we're

82
00:03:52.479 --> 00:03:53.259 A:middle L:90%
just gonna do a 90 degree rotation X. So

83
00:03:53.259 --> 00:03:57.590 A:middle L:90%
we're looking straight down at the character, Uh oops,

84
00:03:57.590 --> 00:04:01.949 A:middle L:90%
that's 90° away from the character. Do 5 units away

85
00:04:01.949 --> 00:04:06.110 A:middle L:90%
away, and we're going to do 90° rotation.

86
00:04:06.120 --> 00:04:09.900 A:middle L:90%
So basically just looking down on the character and you

87
00:04:09.900 --> 00:04:11.500 A:middle L:90%
can use this value to sort of zoom out a bit.

88
00:04:11.500 --> 00:04:15.430 A:middle L:90%
And we can make it orthographic or

89
00:04:15.430 --> 00:04:16.250 A:middle L:90%
perspective. I think orthographic will be more useful

90
00:04:16.250 --> 00:04:23.800 A:middle L:90%
here. So let's have a look at what this

91
00:04:23.800 --> 00:04:26.189 A:middle L:90%
looks like. We'll make our gizmo is just a

92
00:04:26.189 --> 00:04:27.850 A:middle L:90%
little bit smaller, they're pretty huge right now.

93
00:04:28.839 --> 00:04:30.149 A:middle L:90%
So as we run around, we can see our

94
00:04:30.149 --> 00:04:31.230 A:middle L:90%
character from this top view. This will be useful

95
00:04:31.230 --> 00:04:33.779 A:middle L:90%
for debugging until we actually get a camera into our

96
00:04:33.779 --> 00:04:36.459 A:middle L:90%
game. Cool, so that's a good start.

97
00:04:39.740 --> 00:04:41.920 A:middle L:90%
I'm gonna go ahead and make sure that this is

98
00:04:41.920 --> 00:04:44.069 A:middle L:90%
only in play mode and that means that we can

99
00:04:44.079 --> 00:04:46.329 A:middle L:90%
sort of rotate this camera around when we're just in

100
00:04:46.329 --> 00:04:47.800 A:middle L:90%
our normal scene to you. I think it's a

101
00:04:47.800 --> 00:04:50.310 A:middle L:90%
good time right now to just have a moment to

102
00:04:50.310 --> 00:04:54.069 A:middle L:90%
think about why we're building this camera script cause you

103
00:04:54.069 --> 00:04:57.339 A:middle L:90%
might think, okay, so we've got ah locomotion

104
00:04:57.339 --> 00:04:58.810 A:middle L:90%
and everything, but there's like a lot of things

105
00:04:58.810 --> 00:05:00.579 A:middle L:90%
that aren't so great about this locomotion right now,

106
00:05:00.589 --> 00:05:04.860 A:middle L:90%
if you try to navigate these cubes it's extremely difficult,

107
00:05:05.339 --> 00:05:08.970 A:middle L:90%
uh and you notice that from the fact that

108
00:05:08.980 --> 00:05:10.889 A:middle L:90%
if you hold back on the control stick, it

109
00:05:10.889 --> 00:05:12.430 A:middle L:90%
means the same thing as running forward, which is

110
00:05:12.430 --> 00:05:14.439 A:middle L:90%
kind of an intuitive and it's really hard to tell

111
00:05:14.439 --> 00:05:16.089 A:middle L:90%
what direction you're moving. So the camera scripts and

112
00:05:16.089 --> 00:05:18.220 A:middle L:90%
the locomotion scripts that we're gonna be making this tutorial

113
00:05:18.230 --> 00:05:20.819 A:middle L:90%
are going to make a much more intuitive controller for

114
00:05:20.819 --> 00:05:23.079 A:middle L:90%
you to work with and make your game and feel

115
00:05:23.079 --> 00:05:25.029 A:middle L:90%
a lot better and a lot more playable. Right.

116
00:05:25.029 --> 00:05:27.360 A:middle L:90%
So now we're gonna add a camera script to our character.

117
00:05:27.600 --> 00:05:28.649 A:middle L:90%
So we're going to stop this for now.

