1
00:00:00,000 --> 00:00:03,690
Welcome back, my fellow
game developers.

2
00:00:03,690 --> 00:00:06,420
This is a very quick
and short video.

3
00:00:06,420 --> 00:00:09,360
This is just a small tweak
that we want to make.

4
00:00:09,360 --> 00:00:11,540
And the way our
player moves around,

5
00:00:11,535 --> 00:00:13,265
we don't have major cold,

6
00:00:13,260 --> 00:00:14,910
we don't have major principles.

7
00:00:14,910 --> 00:00:17,610
We do have a little
lesson on mathematics,

8
00:00:17,610 --> 00:00:18,960
which is acknowledged the most

9
00:00:18,960 --> 00:00:20,980
exciting part in
game development.

10
00:00:20,984 --> 00:00:23,794
Yay, that's what you came
here for math, right?

11
00:00:23,790 --> 00:00:26,070
Anyways, let's not
waste any more time.

12
00:00:26,070 --> 00:00:27,300
And you can see that

13
00:00:27,300 --> 00:00:29,520
the velocity when we move
diagonal is the same

14
00:00:29,520 --> 00:00:33,240
as when we are moving up
or down or left and right.

15
00:00:33,235 --> 00:00:34,645
Anyways, let's not waste

16
00:00:34,640 --> 00:00:38,020
any more time and
let's get started.

17
00:00:38,015 --> 00:00:39,775
Oh, okay.

18
00:00:39,770 --> 00:00:43,820
So let's see what's
happening in here.

19
00:00:43,820 --> 00:00:45,200
As I've told you,

20
00:00:45,200 --> 00:00:47,650
whenever we are moving
left and right,

21
00:00:47,645 --> 00:00:50,305
we are moving at a
certain velocity.

22
00:00:50,300 --> 00:00:55,450
But when we are moving left
or right and we're moving up,

23
00:00:55,445 --> 00:00:58,825
we are moving at a
much faster speed.

24
00:00:58,820 --> 00:01:01,300
So if you're not convinced,

25
00:01:01,295 --> 00:01:02,515
let's test this out.

26
00:01:02,510 --> 00:01:04,000
Maybe I am lying.

27
00:01:03,995 --> 00:01:05,675
I'm going to go down here.

28
00:01:05,675 --> 00:01:08,785
I'm going to write
debug dot log.

29
00:01:08,780 --> 00:01:12,010
And in here I'm
going to say walking

30
00:01:12,005 --> 00:01:16,405
with a speed of and I'm

31
00:01:16,400 --> 00:01:24,460
going to go ahead and add the
layer rigid body velocity.

32
00:01:24,455 --> 00:01:27,875
Let's save that and
let's see what we have.

33
00:01:27,875 --> 00:01:30,125
Now this might not work.

34
00:01:30,125 --> 00:01:31,615
If I click on the Console,

35
00:01:31,610 --> 00:01:34,780
you'll notice that we have 00.

36
00:01:34,775 --> 00:01:36,505
So now if I move it,

37
00:01:36,500 --> 00:01:37,760
you wouldn't see it stand.

38
00:01:37,760 --> 00:01:38,930
When I move away,

39
00:01:38,930 --> 00:01:41,990
it's minus 10 when I move
up and to the right,

40
00:01:41,990 --> 00:01:44,050
you can see that it's 10 by 10,

41
00:01:44,045 --> 00:01:47,245
and that's the movement speed
that we have right here.

42
00:01:47,240 --> 00:01:49,580
But we don't want to see

43
00:01:49,580 --> 00:01:52,030
how the vector of
the velocity is.

44
00:01:52,025 --> 00:01:53,845
We want to see the magnitude.

45
00:01:53,840 --> 00:01:57,730
So I'm going to add something
called the magnitude.

46
00:01:57,725 --> 00:01:59,965
If you don't know what
the magnitude is,

47
00:01:59,960 --> 00:02:02,170
I'm going to explain
it in just a bit.

48
00:02:02,165 --> 00:02:05,035
So again, we run the game.

49
00:02:05,030 --> 00:02:06,590
Now we have the magnitude 0.

50
00:02:06,590 --> 00:02:07,750
If I walk to the right,

51
00:02:07,745 --> 00:02:10,765
we have done to the
left, we have ten.

52
00:02:10,760 --> 00:02:13,190
If I move up, it's still 10.

53
00:02:13,190 --> 00:02:14,830
You can see it
increasing in here.

54
00:02:14,825 --> 00:02:17,155
If I move down, it's still 10.

55
00:02:17,150 --> 00:02:19,210
But now if I move to the right,

56
00:02:19,205 --> 00:02:22,075
end up, we can see that it's 14.

57
00:02:22,070 --> 00:02:24,710
So Michael, your instructor,

58
00:02:24,710 --> 00:02:27,020
does not lie. Never.

59
00:02:27,020 --> 00:02:29,150
You can see that we are moving

60
00:02:29,150 --> 00:02:31,900
faster when we are
moving diagonally,

61
00:02:31,895 --> 00:02:36,145
up or down by pressing two keys.

62
00:02:36,140 --> 00:02:38,170
Why is that happening?

63
00:02:38,165 --> 00:02:39,925
Well, it comes back.

64
00:02:39,920 --> 00:02:41,470
Simple mathematics.

65
00:02:41,465 --> 00:02:43,315
You can see that we have

66
00:02:43,310 --> 00:02:47,270
the velocity on the y and
the velocity on the x.

67
00:02:47,270 --> 00:02:50,680
That's what we were seeing
before we added the magnitude,

68
00:02:50,675 --> 00:02:52,475
which is 10 by 10.

69
00:02:52,475 --> 00:02:55,595
So what happens here
is we're adding both

70
00:02:55,595 --> 00:02:59,005
of these vectors as we
are moving diagonally.

71
00:02:59,000 --> 00:03:01,930
And we have the final
player velocity,

72
00:03:01,925 --> 00:03:04,835
which is faster than those two.

73
00:03:04,835 --> 00:03:06,355
Now, if you want,

74
00:03:06,350 --> 00:03:07,490
you can keep this in

75
00:03:07,490 --> 00:03:09,680
your game if it's part
of your gameplay.

76
00:03:09,680 --> 00:03:12,080
But usually we don't
want the player to

77
00:03:12,080 --> 00:03:14,630
move faster when he's
moving in a diagonal.

78
00:03:14,630 --> 00:03:16,600
This is not something logical.

79
00:03:16,595 --> 00:03:19,685
So what we'll do is
we'll normalize.

80
00:03:19,685 --> 00:03:23,725
We do by normalizing
is recreate this arc.

81
00:03:23,720 --> 00:03:26,600
And this means this
becomes a circle,

82
00:03:26,600 --> 00:03:28,520
which means that the velocity on

83
00:03:28,520 --> 00:03:30,860
the x plus the velocity on

84
00:03:30,860 --> 00:03:33,140
the y is the same as

85
00:03:33,140 --> 00:03:36,430
the velocity when we are
moving in a diagonal.

86
00:03:36,425 --> 00:03:38,785
So this is a normalized vector,

87
00:03:38,780 --> 00:03:42,920
or when we say
normalizing a vector.

88
00:03:42,920 --> 00:03:45,580
So let's go ahead
and do just that.

89
00:03:45,575 --> 00:03:47,765
So back in our code,

90
00:03:47,765 --> 00:03:49,855
let's go to Visual Studio.

91
00:03:49,850 --> 00:03:52,070
And now let's see where do we

92
00:03:52,070 --> 00:03:54,730
have our velocity being added?

93
00:03:54,725 --> 00:03:56,555
It's right here.

94
00:03:56,555 --> 00:03:59,135
So I'm going to add a,

95
00:03:59,135 --> 00:04:00,695
another line or I'm sorry,

96
00:04:00,695 --> 00:04:03,665
before we add this
to the velocity,

97
00:04:03,665 --> 00:04:05,035
I'm going to take

98
00:04:05,030 --> 00:04:10,400
the movement input and I'm
going to normalize it.

99
00:04:10,400 --> 00:04:12,260
Save that.

100
00:04:12,260 --> 00:04:16,750
So now when we go
back into our game,

101
00:04:16,745 --> 00:04:19,555
and by the way, the
whole process here,

102
00:04:19,550 --> 00:04:22,550
you know that this one
is just taking a value.

103
00:04:22,550 --> 00:04:24,050
Movement speed doesn't change.

104
00:04:24,050 --> 00:04:25,640
So the only variable that's

105
00:04:25,640 --> 00:04:27,410
changing is the movement input.

106
00:04:27,410 --> 00:04:30,350
That's why I normalize
the movement input.

107
00:04:30,350 --> 00:04:32,740
Hence, the velocity
stays the same.

108
00:04:32,735 --> 00:04:34,795
So just if you were confused,

109
00:04:34,790 --> 00:04:37,910
why we're changing the movement
input, not the velocity.

110
00:04:37,910 --> 00:04:40,060
So we go back in here,

111
00:04:40,055 --> 00:04:42,065
we run our game.

112
00:04:42,065 --> 00:04:44,105
And now you can see we
walked to the right.

113
00:04:44,105 --> 00:04:46,645
It Stan, to the
left is still 10,

114
00:04:46,640 --> 00:04:49,280
up, Stan down, it's 10.

115
00:04:49,280 --> 00:04:51,220
When we move in a diagonal.

116
00:04:51,215 --> 00:04:52,235
There we go.

117
00:04:52,235 --> 00:04:55,445
You can see that
it is still done.

118
00:04:55,445 --> 00:04:57,185
How cool is that?

119
00:04:57,185 --> 00:04:58,775
It's amazing.

120
00:04:58,775 --> 00:05:01,595
On a final note, maybe
you want to keep it.

121
00:05:01,595 --> 00:05:03,025
Maybe you want to
make the player

122
00:05:03,020 --> 00:05:04,900
faster as you move diagonally.

123
00:05:04,895 --> 00:05:06,205
That's not a problem.

124
00:05:06,200 --> 00:05:07,660
You can do whatever you want.

125
00:05:07,655 --> 00:05:08,935
This is your game,

126
00:05:08,930 --> 00:05:11,060
add your own flavor to it.

127
00:05:11,060 --> 00:05:15,530
But this is a battle
game development habit

128
00:05:15,530 --> 00:05:17,120
that you should have as

129
00:05:17,120 --> 00:05:19,480
you progress through
your journey.

130
00:05:19,475 --> 00:05:22,105
Well, that said this was
a quick and short video.

131
00:05:22,100 --> 00:05:23,990
Make sure to commit
your changes.

132
00:05:23,990 --> 00:05:26,950
I forgot to commit them
last time, but no worries.

133
00:05:26,945 --> 00:05:29,815
I can keep this player
controller as we've only

134
00:05:29,810 --> 00:05:33,020
changed the debug
dot log in here.

135
00:05:33,020 --> 00:05:35,660
And the normalized,
I can stage these,

136
00:05:35,660 --> 00:05:38,210
commit these changes and
then commit the other ones.

137
00:05:38,210 --> 00:05:40,070
So, well that said,

138
00:05:40,070 --> 00:05:41,510
I hope you enjoy it.

139
00:05:41,510 --> 00:05:44,090
And I believe this is the end of

140
00:05:44,090 --> 00:05:47,540
section 2 where we are going
to be setting up our player.

141
00:05:47,540 --> 00:05:48,960
In the next section,

142
00:05:48,964 --> 00:05:51,414
we are actually
going to start using

143
00:05:51,410 --> 00:05:55,420
our gun to shooting by
adding shooting mechanics.

144
00:05:55,415 --> 00:05:57,965
So I'll see you then.

