1
00:00:00,000 --> 00:00:04,530
Welcome back, My favorite game developers in this video,

2
00:00:04,530 --> 00:00:09,720
when we set the time between shots to 0.1 and we start shooting our birds.

3
00:00:09,720 --> 00:00:13,680
You'll notice that even though they are on top of each other,

4
00:00:13,680 --> 00:00:15,950
they do not destroy themselves,

5
00:00:15,945 --> 00:00:20,195
but they still get destroyed when they hit any wall.

6
00:00:20,190 --> 00:00:25,470
Not only that, if I have a lot of bullets being fired and walk the player through them,

7
00:00:25,470 --> 00:00:27,830
you'll notice that the player also,

8
00:00:27,825 --> 00:00:31,385
or the bullets and the player not interact with each other and

9
00:00:31,380 --> 00:00:35,100
they don't get destroyed upon hitting the layer,

10
00:00:35,100 --> 00:00:36,120
which is a good mechanic.

11
00:00:36,120 --> 00:00:39,920
We don't want the player to use the bullet to be able to kill themselves.

12
00:00:39,915 --> 00:00:41,475
This is a game mechanic.

13
00:00:41,475 --> 00:00:43,165
So with that said,

14
00:00:43,160 --> 00:00:44,870
let's not waste any more time,

15
00:00:44,870 --> 00:00:51,770
and let's get started by learning layer and physics 2D matrix k.

16
00:00:51,770 --> 00:00:55,210
So now when we run our game,

17
00:00:55,205 --> 00:00:57,565
you'll see that we can fire our books.

18
00:00:57,560 --> 00:01:00,350
But the problem is if we try to press it multiple

19
00:01:00,350 --> 00:01:03,680
times or if we set the time between shots,

20
00:01:03,680 --> 00:01:08,930
for example, 0.1, you'll see that we don't see any bullets flying away.

21
00:01:08,930 --> 00:01:09,350
Why?

22
00:01:09,350 --> 00:01:11,380
Because notice on the left,

23
00:01:11,375 --> 00:01:14,245
we have the bullets firing and destroying

24
00:01:14,240 --> 00:01:18,220
themselves because they are interacting with each other.

25
00:01:18,215 --> 00:01:19,765
And we don't want that.

26
00:01:19,760 --> 00:01:21,740
We want to fix this problem.

27
00:01:21,740 --> 00:01:23,890
How are we going to do this?

28
00:01:23,885 --> 00:01:25,565
Now before we continue on,

29
00:01:25,565 --> 00:01:28,655
maybe it's something that you do want to keep in your game.

30
00:01:28,655 --> 00:01:30,025
But honestly for me,

31
00:01:30,020 --> 00:01:33,880
it's kind of annoying having your bullets be destroyed.

32
00:01:33,875 --> 00:01:37,915
So again, how are we going to fix this?

33
00:01:37,910 --> 00:01:43,070
Well, if we look right here on the right and the inspector of any game object,

34
00:01:43,070 --> 00:01:46,030
we can see that we have something called the layer.

35
00:01:46,025 --> 00:01:50,095
And I've showed you this previously when we were talking about sorting layers,

36
00:01:50,090 --> 00:01:53,080
but we haven't delved deep into it.

37
00:01:53,075 --> 00:01:55,405
So if I go back to layers,

38
00:01:55,400 --> 00:02:00,820
you can see that I have tags which we will talk about In the future.

39
00:02:00,815 --> 00:02:04,465
We have the sorting layers which determine which Sprite

40
00:02:04,460 --> 00:02:08,450
or which layer renders in front of which other layer.

41
00:02:08,450 --> 00:02:11,060
And we also have the layers.

42
00:02:11,060 --> 00:02:13,750
And you can see that we already have the default

43
00:02:13,745 --> 00:02:17,035
transparent affects, ignore re-cast water.

44
00:02:17,030 --> 00:02:23,240
You are all of these different layers that are already present in Unity.

45
00:02:23,240 --> 00:02:29,480
So what we're going to do is we are going to set the bullets on a certain layer.

46
00:02:29,480 --> 00:02:34,070
You might be asking, but why should we be setting these bullets on a certain layer?

47
00:02:34,070 --> 00:02:42,340
Well, let me show you by first creating the player bullets layer.

48
00:02:42,335 --> 00:02:46,555
Now, we want to go into the projects.

49
00:02:46,550 --> 00:02:50,710
Go into our where are the prefabs, the pleasurable it?

50
00:02:50,705 --> 00:02:55,445
And let's just set the player bullet on the player bullets layer.

51
00:02:55,445 --> 00:02:57,355
Okay, So this was the prefab.

52
00:02:57,350 --> 00:02:59,960
So all subsequent creation or

53
00:02:59,960 --> 00:03:03,590
clones of this prefab will also be on the player bullet layer.

54
00:03:03,590 --> 00:03:06,400
But still, how is this helping us?

55
00:03:06,395 --> 00:03:09,325
Well, if we go into our edit,

56
00:03:09,320 --> 00:03:11,590
into our project settings,

57
00:03:11,585 --> 00:03:15,005
and if we go into the physics 2D and scroll down,

58
00:03:15,005 --> 00:03:19,205
we can see right here this layer collision matrix.

59
00:03:19,205 --> 00:03:20,795
And if you, sorry,

60
00:03:20,795 --> 00:03:22,105
if you tilt your head,

61
00:03:22,100 --> 00:03:24,370
you can see, let me maximize this.

62
00:03:24,365 --> 00:03:28,975
You can see that we have the default transparent re-cast player bullets,

63
00:03:28,970 --> 00:03:31,760
water UI, and on this side also.

64
00:03:31,760 --> 00:03:34,540
So how does this matrix work?

65
00:03:34,535 --> 00:03:37,345
Let's say we have the default layer,

66
00:03:37,340 --> 00:03:39,760
which was previously the bullets layer.

67
00:03:39,755 --> 00:03:45,605
And we can see that it also interacts right here with the default layer on this side.

68
00:03:45,605 --> 00:03:49,765
So what we can do is we can actually turn this off.

69
00:03:49,760 --> 00:03:54,710
So now the default layer does not interact with the other default layers.

70
00:03:54,710 --> 00:03:59,810
But obviously we don't want that to happen because whenever you create a game object,

71
00:03:59,810 --> 00:04:01,960
you will have it as default.

72
00:04:01,955 --> 00:04:04,975
And maybe we do want some of the default

73
00:04:04,970 --> 00:04:08,360
game objects interacting with other default game objects.

74
00:04:08,360 --> 00:04:11,800
And that's why we created the player bullet.

75
00:04:11,795 --> 00:04:14,575
What we can do is we can say that the player bullet,

76
00:04:14,570 --> 00:04:15,880
which is right here,

77
00:04:15,875 --> 00:04:19,135
does not interact with the player bullet.

78
00:04:19,130 --> 00:04:21,080
So we turn this off.

79
00:04:21,080 --> 00:04:25,220
And now the player bullets should not destroy

80
00:04:25,219 --> 00:04:29,829
each other because they will not be able to interact with each other.

81
00:04:29,825 --> 00:04:31,115
Let's test this out.

82
00:04:31,115 --> 00:04:32,585
I'm going to go back.

83
00:04:32,585 --> 00:04:35,245
I'm going to run the game.

84
00:04:35,240 --> 00:04:38,840
And I'm going to go to the DOM player and okay,

85
00:04:38,840 --> 00:04:42,770
so the time between shots will be 0.1.

86
00:04:42,770 --> 00:04:45,110
And let's try to hold down the mouse button.

87
00:04:45,110 --> 00:04:48,190
Now when I hold down the mouse button, there you go.

88
00:04:48,185 --> 00:04:49,685
You can see that the bullets,

89
00:04:49,685 --> 00:04:52,195
even though they are on top of each other,

90
00:04:52,190 --> 00:04:54,350
are not destroying themselves,

91
00:04:54,350 --> 00:04:59,140
but they are still getting destroyed when they hit a wall.

92
00:04:59,135 --> 00:05:02,755
So you can see that clearly when we shoot towards the wall,

93
00:05:02,750 --> 00:05:07,510
but they are on top of each other and they do not destroy themselves.

94
00:05:07,505 --> 00:05:09,505
How cool is that?

95
00:05:09,500 --> 00:05:14,390
We have this powerful tool in our arsenal now where we can set

96
00:05:14,390 --> 00:05:16,910
different objects to different layers

97
00:05:16,910 --> 00:05:19,640
and make sure that they don't interact with each other.

98
00:05:19,640 --> 00:05:26,410
Now, another thing that we might want to change is the player bullets hitting the player.

99
00:05:26,405 --> 00:05:27,125
Again.

100
00:05:27,125 --> 00:05:30,905
I tell you, if you do want to keep this mechanic in your game,

101
00:05:30,905 --> 00:05:32,305
feel free to do it.

102
00:05:32,300 --> 00:05:36,710
If you don't, we are going to change the way bullets interact with the player.

103
00:05:36,710 --> 00:05:41,600
Now, currently, the player capsule collider is very small.

104
00:05:41,600 --> 00:05:44,810
What we can do is we can add another capsule collider.

105
00:05:44,810 --> 00:05:50,060
We will have to later on because what happens if one of the enemies shoots a bullet

106
00:05:50,060 --> 00:05:52,640
at our head and we don't have a collider

107
00:05:52,640 --> 00:05:55,520
there that does not register that we've been shot.

108
00:05:55,520 --> 00:05:56,630
We will fix that.

109
00:05:56,630 --> 00:06:02,270
But for now, let's just keep things simple and try to hit the player on his legs.

110
00:06:02,265 --> 00:06:04,095
So I'm going to run the game.

111
00:06:04,090 --> 00:06:05,490
I'm going to shoot a bullet.

112
00:06:05,485 --> 00:06:06,885
And if I stop there,

113
00:06:06,880 --> 00:06:10,930
you can see that it hits the player and can kill him. Again.

114
00:06:10,930 --> 00:06:12,490
You want to keep those mechanics.

115
00:06:12,490 --> 00:06:15,070
You want the player bullets to help the player.

116
00:06:15,070 --> 00:06:16,050
That's okay.

117
00:06:16,045 --> 00:06:19,685
But you will have to this challenge.

118
00:06:19,689 --> 00:06:23,789
You'll need to make sure that the player and the bullets won't interact.

119
00:06:23,785 --> 00:06:26,815
So create a layer, layer.

120
00:06:26,815 --> 00:06:29,665
Assign the player to that layer,

121
00:06:29,665 --> 00:06:33,205
and make sure that the player and the player bullets

122
00:06:33,205 --> 00:06:36,775
do not interact through the physics matrix.

123
00:06:36,775 --> 00:06:39,955
So that said, pause the video right now,

124
00:06:39,955 --> 00:06:41,505
go create the player layer.

125
00:06:41,500 --> 00:06:44,760
Make sure the bullets don't kill our player.

126
00:06:44,760 --> 00:06:47,180
Okay, welcome back.

127
00:06:47,180 --> 00:06:49,760
So how did you get on with that?

128
00:06:49,760 --> 00:06:51,490
Before I continue on,

129
00:06:51,485 --> 00:06:52,975
I just want to do something.

130
00:06:52,970 --> 00:06:55,120
I told you I wouldn't want to do it,

131
00:06:55,115 --> 00:06:56,465
but let's do it for now.

132
00:06:56,465 --> 00:06:59,255
I'm going to add a box collider to the player.

133
00:06:59,255 --> 00:07:01,915
This will not be where the player interacts.

134
00:07:01,910 --> 00:07:06,470
This will be just a box collider to determine that the player is being hit.

135
00:07:06,470 --> 00:07:11,410
So I'm going to make it around the size of the player and I'm going to make it

136
00:07:11,405 --> 00:07:16,465
a trigger because I don't want this box collider to interact with the world physically.

137
00:07:16,460 --> 00:07:20,090
I want to keep this box collider as a registered to if

138
00:07:20,090 --> 00:07:24,040
someone has deep layer or some kind of layer.

139
00:07:24,035 --> 00:07:26,545
So I'm going to save this.

140
00:07:26,540 --> 00:07:28,270
I'm going to run the game.

141
00:07:28,265 --> 00:07:30,355
Obviously, we'll need to override the prefab.

142
00:07:30,350 --> 00:07:32,780
I'm going to shoot this and if I walked towards the bullet,

143
00:07:32,780 --> 00:07:35,480
you can see that it hits the player.

144
00:07:35,480 --> 00:07:39,350
So let's go ahead into the layers appear.

145
00:07:39,350 --> 00:07:41,600
At layers, open the layers.

146
00:07:41,600 --> 00:07:45,230
I am going to add the player layer.

147
00:07:45,230 --> 00:07:48,500
And now I'm going to go into the doom player.

148
00:07:48,500 --> 00:07:53,740
I'm going to go into the Layers and I'm going to set this layer to the player layer.

149
00:07:53,735 --> 00:07:58,085
And you can see that when you change the layer of a parent, you get the option.

150
00:07:58,085 --> 00:07:59,915
Do you want to set the player,

151
00:07:59,915 --> 00:08:04,675
the player to player for all the child objects as well.

152
00:08:04,670 --> 00:08:06,850
Would you want to do that or not?

153
00:08:06,845 --> 00:08:10,325
I think it wouldn't harm if we set the children also.

154
00:08:10,325 --> 00:08:12,205
So I'm going to set this,

155
00:08:12,200 --> 00:08:13,760
I'm going to save this.

156
00:08:13,760 --> 00:08:17,720
I'm going to go into the project settings, physics,

157
00:08:17,720 --> 00:08:24,310
and I'm going to make sure that the player bullets and the player do not interact.

158
00:08:24,305 --> 00:08:28,325
So you can see where there is an intersection between the player bullets.

159
00:08:28,325 --> 00:08:34,345
The player. I'm going to make sure that there is no sign in here. There we go.

160
00:08:34,340 --> 00:08:35,720
Now if we run the game,

161
00:08:35,720 --> 00:08:39,020
the bullets should travel through the player.

162
00:08:39,020 --> 00:08:40,610
And yep, there we go.

163
00:08:40,610 --> 00:08:43,540
So we can shoot the bullets as many times as we want,

164
00:08:43,535 --> 00:08:45,415
and they do not hit the player.

165
00:08:45,410 --> 00:08:49,370
They keep floating until they hit some kind of enemy.

166
00:08:49,370 --> 00:08:51,160
So I hope you enjoy,

167
00:08:51,155 --> 00:08:54,385
I hope you like this new tool that you have.

168
00:08:54,380 --> 00:09:00,530
We can also apply all of our changes to the prefab that we have of the dome player.

169
00:09:00,530 --> 00:09:02,720
And in the next video,

170
00:09:02,720 --> 00:09:06,290
you'll notice that we have these bullets,

171
00:09:06,290 --> 00:09:07,480
okay, they are firing.

172
00:09:07,475 --> 00:09:08,815
It's, everything is nice,

173
00:09:08,810 --> 00:09:10,510
but when they hit a wall,

174
00:09:10,505 --> 00:09:12,275
there is nothing that's happening.

175
00:09:12,275 --> 00:09:15,325
The bullet is just disappearing and that's not very exciting.

176
00:09:15,320 --> 00:09:17,750
We want to have some kind of impact,

177
00:09:17,750 --> 00:09:19,070
some kind of effects,

178
00:09:19,070 --> 00:09:23,080
or we can feel the weight of those bullets hitting a wall.

179
00:09:23,075 --> 00:09:26,275
And that's exactly what we'll do in the next video by adding

180
00:09:26,270 --> 00:09:29,470
the special effects to the bullet upon impact.

181
00:09:29,465 --> 00:09:32,635
So don't forget to commit your changes.

182
00:09:32,630 --> 00:09:36,540
And I'll see you in the next video.

