Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,080 --> 00:00:04,880
Now that the projectiles by themselves are complete, we want to implement a way for the player to actually
2
00:00:04,880 --> 00:00:07,820
shoot them instead of us having to drag them into the world.
3
00:00:08,330 --> 00:00:11,960
First, we can go here to the projectile and just hit delete on the keyboard.
4
00:00:11,960 --> 00:00:15,590
Get rid of this one because we want to spawn it when shooting.
5
00:00:15,980 --> 00:00:21,290
The first thing we need for that is of course a button binding, because now we only have a button for
6
00:00:21,290 --> 00:00:25,220
moving and for jumping, but we need to set up buttons for the shooting.
7
00:00:25,220 --> 00:00:28,550
And if you remember, we use the enhanced input system for that.
8
00:00:28,550 --> 00:00:31,460
So we can go to content go to input.
9
00:00:31,460 --> 00:00:33,530
And we need to create a new action.
10
00:00:33,530 --> 00:00:40,010
And I can just right click here go to input and Input action just called IA shoot.
11
00:00:40,740 --> 00:00:45,330
And in here we don't have to change anything because it is just a button digital wool.
12
00:00:45,330 --> 00:00:48,570
It can either be active or not active.
13
00:00:49,330 --> 00:00:52,330
And we then need to go to our IMC action.
14
00:00:52,330 --> 00:00:55,660
And here we also need to set up the button for shooting.
15
00:00:55,660 --> 00:01:00,820
And if you remember, I set the spacebar for jumping, but also K because if we only have the spacebar
16
00:01:00,820 --> 00:01:01,930
it kind of gets awkward.
17
00:01:01,930 --> 00:01:04,030
Like where do we put the shoot button.
18
00:01:04,030 --> 00:01:08,710
So if I add the mapping here go to I shoot.
19
00:01:09,220 --> 00:01:13,960
And here open it up I want to put this on J.
20
00:01:13,960 --> 00:01:16,690
Because now we have shooting on J and jumping on K.
21
00:01:16,690 --> 00:01:20,140
So we have the same position on the keyboard as ten finger typing.
22
00:01:20,750 --> 00:01:22,220
Now we can save this.
23
00:01:22,220 --> 00:01:25,190
And we of course need to set this up in the player.
24
00:01:25,190 --> 00:01:31,190
So in the content drawer go to blueprints Characters player and the BP player.
25
00:01:33,870 --> 00:01:35,700
On the event graph, right?
26
00:01:35,700 --> 00:01:37,560
If you're not here, click on the event graph.
27
00:01:37,560 --> 00:01:39,330
We have our jump event.
28
00:01:39,330 --> 00:01:40,350
We have our move event.
29
00:01:40,350 --> 00:01:45,960
So down here you can just right click and go for IA shoot which we just created.
30
00:01:46,720 --> 00:01:49,360
And spawning a projectile is extremely easy.
31
00:01:49,360 --> 00:01:53,410
So here again we don't want to use triggered because triggered happens on every frame that the button
32
00:01:53,410 --> 00:01:54,220
is being held.
33
00:01:54,220 --> 00:01:58,420
We just want to shoot on started when we press the button for the first time.
34
00:01:58,420 --> 00:02:02,860
And here we can just spawn actor from class.
35
00:02:04,070 --> 00:02:09,470
And this just lets us pick any class that we have created or classes that are available in Unreal Engine
36
00:02:09,470 --> 00:02:13,370
from the get go, and here we can just look for our projectile.
37
00:02:13,940 --> 00:02:20,570
And for this one, let's first just start out with the BP player projectile regular, because this is
38
00:02:20,570 --> 00:02:22,010
our default projectile.
39
00:02:22,010 --> 00:02:25,370
And later on, based on some conditions, we're going to have to pick between the regular one, the
40
00:02:25,370 --> 00:02:26,900
partially charged one and the charged one.
41
00:02:26,900 --> 00:02:29,120
But for now, just the regular one.
42
00:02:29,270 --> 00:02:35,000
And the thing we have to give it is a spawn transform, because we can spawn the actor, but we have
43
00:02:35,000 --> 00:02:39,770
to tell him where is it supposed to spawn, which rotation is it supposed to have, which scale is it
44
00:02:39,770 --> 00:02:40,700
supposed to have?
45
00:02:40,700 --> 00:02:44,240
And usually we just want to right click this split struct pin.
46
00:02:44,240 --> 00:02:48,110
We usually don't want to mess with the scale, otherwise the pixel art is going to scale with it and
47
00:02:48,110 --> 00:02:49,250
it's going to look very nasty.
48
00:02:49,250 --> 00:02:52,850
So usually you just keep this as one for the location.
49
00:02:52,850 --> 00:02:58,370
Let's just start out simply by using the player's location so we can get actor location.
50
00:02:58,790 --> 00:03:02,630
And later on we're going to have an offset and want to shoot it actually from the gun.
51
00:03:02,630 --> 00:03:04,130
But for now, just start with this.
52
00:03:04,130 --> 00:03:08,600
And here again just get actor rotation to always shoot forward.
53
00:03:08,600 --> 00:03:12,890
And this is the simple way we can start and then we can make adjustments to it.
54
00:03:12,980 --> 00:03:17,210
And for the collision handling override, just to make sure nothing is going to prevent this from spawning.
55
00:03:17,210 --> 00:03:19,610
Just say always spawn ignore collision.
56
00:03:19,730 --> 00:03:24,890
One more cool thing we can do if we spawn an actor, we can actually set the instigator.
57
00:03:24,890 --> 00:03:28,670
And if we press here, we can also set the owner.
58
00:03:28,670 --> 00:03:33,440
And if you don't have any experience with this, you might not know why this is useful, but this is
59
00:03:33,440 --> 00:03:36,530
a very easy way to pass a reference into this actor.
60
00:03:36,530 --> 00:03:42,470
So inside of this actor, we can then just get owner and can perform certain actions on the owner.
61
00:03:42,470 --> 00:03:45,770
So we're going to use this later for the shot recovery.
62
00:03:45,770 --> 00:03:49,400
Like I said before, we have to destroy the projectiles if they leave the screen.
63
00:03:49,400 --> 00:03:54,290
And then if a projectile is destroyed, we need to tell the player, hey, it was destroyed, you can
64
00:03:54,290 --> 00:03:55,460
shoot again.
65
00:03:55,460 --> 00:04:00,710
And for that it is really useful if we just pass a reference of the player in here.
66
00:04:00,710 --> 00:04:02,630
So for owner we can just get self.
67
00:04:03,540 --> 00:04:09,030
And we can also set this to the instigator, because the owner in this case is also the instigator.
68
00:04:09,330 --> 00:04:12,390
And this is all it takes to simply spawn a projectile.
69
00:04:12,390 --> 00:04:13,890
So let's try this out.
70
00:04:14,100 --> 00:04:16,350
And we want to get out of simulation mode.
71
00:04:16,350 --> 00:04:18,450
Just go back to selected viewport.
72
00:04:20,279 --> 00:04:21,329
And again, very important.
73
00:04:21,329 --> 00:04:24,150
Click into the viewport to take control of the character.
74
00:04:24,150 --> 00:04:25,230
If I press J.
75
00:04:25,230 --> 00:04:29,460
Now you can see that we spawn the projectile and there are a couple of issues.
76
00:04:29,460 --> 00:04:33,630
Now you can see that we are being pushed back by the projectile and it instantly explodes.
77
00:04:33,630 --> 00:04:36,360
And this is because of the collision settings.
78
00:04:36,360 --> 00:04:38,670
And this is the next thing we want to do.
79
00:04:38,700 --> 00:04:43,890
We want to make sure that the projectile is blocking with walls, but it is only overlapping with characters,
80
00:04:43,890 --> 00:04:46,290
so that weird things like this don't happen.
81
00:04:46,290 --> 00:04:49,530
So now we want to open up the projectile base.
82
00:04:49,860 --> 00:04:57,360
So go to content blueprints projectiles and yeah, the projectile base because we want to apply this
83
00:04:57,360 --> 00:04:58,680
to all projectiles.
84
00:05:00,190 --> 00:05:03,370
And here we want to select the sphere because the spheres are collision.
85
00:05:03,370 --> 00:05:07,870
And on the right side scroll down until we find the collision settings.
86
00:05:07,870 --> 00:05:10,720
And here you can see here we have block all dynamic.
87
00:05:10,720 --> 00:05:14,080
And the problem here is that we are blocking the pawn.
88
00:05:14,080 --> 00:05:16,210
And the player's capsule is a pawn.
89
00:05:16,210 --> 00:05:21,820
So if we spawn the bullet we kind of push ourselves away because they cannot exist in the same space.
90
00:05:21,820 --> 00:05:26,140
We want to set this to overlap, but as you can see, we cannot select anything here.
91
00:05:26,290 --> 00:05:31,840
A very quick and dirty way of doing this is to just go here and set this to custom.
92
00:05:32,420 --> 00:05:36,950
And for --, we just go to overlap and this is it, right?
93
00:05:36,950 --> 00:05:38,330
So now we can go back here.
94
00:05:39,020 --> 00:05:40,490
I can press play.
95
00:05:41,020 --> 00:05:42,850
And we have solved the issue.
96
00:05:43,300 --> 00:05:46,270
And in many cases this is a good enough solution.
97
00:05:46,390 --> 00:05:49,360
But the projectiles are actually very important for our game.
98
00:05:49,360 --> 00:05:53,710
So I think we should implement a custom channel for the projectiles just to make sure we manage them
99
00:05:53,710 --> 00:05:54,160
correctly.
100
00:05:54,160 --> 00:05:57,280
And don't just set everything to custom and then lose track of things.
101
00:05:57,280 --> 00:06:02,770
We can easily create a new item on this list by going to Edit Project Settings.
102
00:06:04,720 --> 00:06:06,550
And under engine.
103
00:06:06,550 --> 00:06:07,900
We have collision.
104
00:06:07,930 --> 00:06:08,350
Right.
105
00:06:08,350 --> 00:06:09,310
Engine collision.
106
00:06:09,310 --> 00:06:10,180
Click here.
107
00:06:10,270 --> 00:06:14,860
In here we have the object channels, the trace channels and the presets.
108
00:06:15,400 --> 00:06:18,310
An object channel is something you can see here right.
109
00:06:18,310 --> 00:06:19,390
The object type.
110
00:06:19,390 --> 00:06:22,240
If we add another object channel it's going to show up in this list.
111
00:06:22,240 --> 00:06:27,070
And it's also going to create another entry down here which we can then assign things to.
112
00:06:28,800 --> 00:06:33,870
So we're first going to use this so we can create a new object channel just called projectile.
113
00:06:34,740 --> 00:06:39,450
And for this one we can also set the default response and it could be ignored, overlap or block.
114
00:06:39,450 --> 00:06:45,270
And in this case block is the best one because as I said before, for blocking to actually work, two
115
00:06:45,270 --> 00:06:47,160
objects need to block each other.
116
00:06:47,160 --> 00:06:49,830
If only one side blocks and the other one only overlaps.
117
00:06:49,860 --> 00:06:54,990
Overlap is the one that is actually going to be active, so it is safer to have it on block by default,
118
00:06:54,990 --> 00:06:58,320
and we can then make changes in the projectile itself.
119
00:06:58,590 --> 00:07:00,360
So here we can just click on accept.
120
00:07:00,840 --> 00:07:04,440
And just look at the projectile compile for this to show up.
121
00:07:04,440 --> 00:07:06,900
And now here we can see that we have the projectile.
122
00:07:06,900 --> 00:07:09,510
Here we have the projectile here as well.
123
00:07:09,510 --> 00:07:09,810
Right.
124
00:07:09,810 --> 00:07:11,430
So we added this to the list.
125
00:07:11,430 --> 00:07:12,780
And this is fine right.
126
00:07:12,780 --> 00:07:15,150
We could just say oh this is a projectile.
127
00:07:15,150 --> 00:07:20,970
And then we can say it should only ignore other projectiles or overlap other projectiles.
128
00:07:20,970 --> 00:07:25,050
But again this is a little bit hard to manage if we want to use this over multiple blueprints.
129
00:07:25,050 --> 00:07:27,810
So we also want to add a collision preset here.
130
00:07:27,810 --> 00:07:29,250
So we can just pick it from the list.
131
00:07:29,250 --> 00:07:32,430
And all of these settings down here are always going to be the same.
132
00:07:32,430 --> 00:07:34,890
And we can do this here again in project settings.
133
00:07:34,890 --> 00:07:36,900
So trace channels we don't have to worry about.
134
00:07:36,900 --> 00:07:40,530
Now these are for line traces and things like that for the camera tracing.
135
00:07:40,530 --> 00:07:42,930
But presets are the one we want right.
136
00:07:42,930 --> 00:07:47,430
So this preset collision preset we want to add one here.
137
00:07:47,880 --> 00:07:49,380
And we can just click on new.
138
00:07:50,280 --> 00:07:53,040
And the name is going to be projectile again.
139
00:07:53,280 --> 00:07:55,380
And we need to set up collision enabled.
140
00:07:55,380 --> 00:08:00,180
So this just means no collision query only is if you're only looking for overlap events.
141
00:08:00,180 --> 00:08:03,270
If you don't care about physics, if you don't care about block events.
142
00:08:03,270 --> 00:08:04,680
But we actually do.
143
00:08:04,680 --> 00:08:06,990
And physics is only block events, things like that.
144
00:08:06,990 --> 00:08:09,660
But we actually want both because we want to look for overlaps.
145
00:08:09,660 --> 00:08:10,890
We also want to look for blocking.
146
00:08:10,890 --> 00:08:14,970
So collision enabled query and physics is the correct one in this case.
147
00:08:14,970 --> 00:08:18,900
For object type we want to pick our projectile which we created before.
148
00:08:18,900 --> 00:08:25,500
And for the description we can just write something here like used for all types of projectiles.
149
00:08:27,040 --> 00:08:29,560
And here we can then set up our channels.
150
00:08:29,560 --> 00:08:32,110
So actually the default we want to have is ignore.
151
00:08:32,110 --> 00:08:37,330
Because most of these things we don't really care about we do want to be blocking world static.
152
00:08:37,330 --> 00:08:41,080
We do want to be blocking world dynamic like the floor we had before.
153
00:08:41,860 --> 00:08:45,670
We don't want to be blocking pawns, but we want an overlap event.
154
00:08:45,670 --> 00:08:47,470
So we want to be overlapping pawns.
155
00:08:47,470 --> 00:08:48,970
We don't care what physics body.
156
00:08:48,970 --> 00:08:51,910
This is the collision site of a static mesh and things like that.
157
00:08:51,910 --> 00:08:53,200
We don't care about vehicles.
158
00:08:53,200 --> 00:08:56,230
We don't care about destructible and projectiles.
159
00:08:56,230 --> 00:09:00,760
Well, maybe if you want to have something where two projectiles can like hit each other and cancel
160
00:09:00,760 --> 00:09:03,250
each other out, we would want to overlap.
161
00:09:03,250 --> 00:09:07,540
We're not going to implement this in this game, but because the possibility of that is there, I think
162
00:09:07,540 --> 00:09:08,920
it's better to set it to overlap.
163
00:09:08,920 --> 00:09:12,880
So we have the option later and we then click on accept.
164
00:09:13,390 --> 00:09:13,930
Right.
165
00:09:13,930 --> 00:09:18,670
And this is all it takes for us to create a new object channel and a new preset.
166
00:09:18,670 --> 00:09:20,710
So again compile and save here.
167
00:09:20,710 --> 00:09:25,990
And we then have the collision presets instead of custom we just pick our projectile.
168
00:09:25,990 --> 00:09:30,010
And everything in here is now just set up the way we did it in the project settings.
169
00:09:30,010 --> 00:09:33,970
And we can then reuse this collision preset over multiple blueprints.
170
00:09:34,590 --> 00:09:37,410
And again, this just does the same thing we did with custom.
171
00:09:37,410 --> 00:09:38,670
But this is a lot cleaner.
172
00:09:38,670 --> 00:09:39,900
It's more reusable.
173
00:09:39,900 --> 00:09:45,690
And this is something I found very intimidating as a beginner to go in here and set all of this up because
174
00:09:45,690 --> 00:09:47,790
there's so many different settings and you're not quite sure.
175
00:09:47,790 --> 00:09:51,990
So I hope this explanation gave you some more confidence in actually using these custom channels by
176
00:09:51,990 --> 00:09:54,960
yourself as well, because it's actually not that hard to use them.
177
00:09:54,960 --> 00:10:00,210
Now again, we can just go back to the map and test this out so start and I can shoot.
178
00:10:00,450 --> 00:10:01,500
It's all good.
179
00:10:01,500 --> 00:10:02,970
We don't block the player.
180
00:10:02,970 --> 00:10:05,070
We don't care about the overlap events yet.
181
00:10:05,070 --> 00:10:07,680
That's something we're going to use once we have the enemies implemented.
182
00:10:07,680 --> 00:10:10,380
But this set up the groundwork for that.
183
00:10:10,800 --> 00:10:14,250
And just to show you, blocking with the wall is also still working.
184
00:10:15,220 --> 00:10:19,480
And even though functionally our shooting is working now, it still doesn't look great, right?
185
00:10:19,480 --> 00:10:24,250
We aren't playing an animation and the bullets are just coming outside the middle of the body of our
186
00:10:24,250 --> 00:10:24,790
character.
187
00:10:24,790 --> 00:10:26,290
So we want to adjust the position.
188
00:10:26,290 --> 00:10:31,480
We want to play animations, and we also want to make sure that we can't just spam and shoot infinitely.
189
00:10:31,480 --> 00:10:33,970
And we're going to take care of this one by one.
190
00:10:33,970 --> 00:10:39,460
The shoot animation for these Mega man type of games is usually very different from most other games.
191
00:10:39,460 --> 00:10:43,240
In most other games, shoot animations have a startup of a couple of frames.
192
00:10:43,240 --> 00:10:47,230
They have some active frames where the movement is going to be locked while you shoot, and then they
193
00:10:47,230 --> 00:10:48,910
have some recovery frames.
194
00:10:48,910 --> 00:10:52,660
And this is just an example of a beat'em up I'm making where this is true.
195
00:10:52,660 --> 00:10:57,370
The character takes some time to prepare the projectile shoots, it is locked in place and then can
196
00:10:57,370 --> 00:10:59,350
start walking again after the recovery.
197
00:10:59,350 --> 00:11:02,350
However, in these games it's actually quite different.
198
00:11:02,350 --> 00:11:07,480
Usually the shoot animation is instant once you press the button and you can keep on walking around
199
00:11:07,480 --> 00:11:10,270
even while you're shooting, you're not locked in place or anything.
200
00:11:10,270 --> 00:11:15,640
There is no recovery and you can also like shoot multiple times right after another if you have the
201
00:11:15,640 --> 00:11:16,630
shot energy.
202
00:11:17,210 --> 00:11:21,710
So the way we have to implement this is a little bit different, and we have to think of it more as
203
00:11:21,710 --> 00:11:25,010
a state rather than a one off animation.
204
00:11:25,010 --> 00:11:30,710
And the shoot animation can also seamlessly transition between idle walking, jumping, falling, and
205
00:11:30,710 --> 00:11:31,940
a lot of different states.
206
00:11:31,940 --> 00:11:35,450
And here's just a simple graphic of what this is going to look like.
207
00:11:35,450 --> 00:11:37,460
We're gonna have the regular idle animation.
208
00:11:37,460 --> 00:11:43,160
We're gonna have the shooting, idle animation, regular run animation, the shooting run animation,
209
00:11:43,160 --> 00:11:48,620
regular jump rise animation, shooting jump, rise, falling, regular and falling while shooting.
210
00:11:48,620 --> 00:11:50,420
And we can seamlessly transition.
211
00:11:50,420 --> 00:11:53,300
So if we start shooting while idle, we'll go into this state.
212
00:11:53,300 --> 00:11:55,850
And the shooting state will stay active for a while.
213
00:11:55,850 --> 00:12:00,590
So even if we stop shooting but we go into the walk animation, it will then transition from this to
214
00:12:00,590 --> 00:12:04,910
this and then over here, and then it will just go back to the regular run state.
215
00:12:04,910 --> 00:12:10,340
And this might sound very complicated to implement, but Paper XRD makes it very easy to do this in
216
00:12:10,340 --> 00:12:10,880
the game.
217
00:12:10,880 --> 00:12:13,910
We just need to add a boolean to the player first.
218
00:12:14,090 --> 00:12:17,870
So here we can go to variables and click on here.
219
00:12:17,870 --> 00:12:20,300
And just called is shooting.
220
00:12:20,630 --> 00:12:23,750
And this should be a boolean because this can only be true or false.
221
00:12:23,750 --> 00:12:25,670
We want to compile and save.
222
00:12:25,670 --> 00:12:30,890
The default value should be false because we are not shooting if we spawn in and then before we spawn
223
00:12:30,890 --> 00:12:37,520
the projectile after we press the shoot action, we can drag this out here and set is shooting.
224
00:12:37,520 --> 00:12:40,520
Connect this here to true very important.
225
00:12:40,520 --> 00:12:41,240
Click here.
226
00:12:42,010 --> 00:12:47,170
To make sure we set shooting to true, and then we spawn the projectile later on.
227
00:12:47,170 --> 00:12:51,010
We're also going to have to set this to false again, but for now let's just set up the animation.
228
00:12:51,190 --> 00:12:57,250
So open up the content drawer in the blueprints characters player.
229
00:12:57,250 --> 00:13:00,220
We have the ABP player the Animation Blueprint.
230
00:13:00,220 --> 00:13:01,480
So open this up.
231
00:13:01,600 --> 00:13:08,170
And like I said before, in the event graph we get a reference to the player and save the owning player
232
00:13:08,170 --> 00:13:08,650
here.
233
00:13:08,650 --> 00:13:15,820
And this is great because now we can simply go anywhere and just ask for is shooting.
234
00:13:15,970 --> 00:13:20,320
And this will allow us to set the state in our animation graph.
235
00:13:20,320 --> 00:13:21,880
So not just here in the event graph.
236
00:13:21,880 --> 00:13:25,900
Also in the animation graph we can now go here and let's start with the idle.
237
00:13:25,900 --> 00:13:27,610
So we can go into the idle.
238
00:13:27,610 --> 00:13:34,930
And here like we used before, we can just go to the output animation and select animation by bool.
239
00:13:35,550 --> 00:13:39,480
And this is a perfect use case for this node.
240
00:13:39,480 --> 00:13:44,280
So we can then get the owning player and is shooting.
241
00:13:45,160 --> 00:13:49,030
Just straighten this up with Q and select this as the condition.
242
00:13:49,480 --> 00:13:54,790
So if we are not shooting so false animation just play idle.
243
00:13:55,500 --> 00:13:56,700
Just like we did before.
244
00:13:56,700 --> 00:14:00,060
But if we are shooting, we want to play.
245
00:14:00,090 --> 00:14:01,980
Ideal shoot.
246
00:14:02,310 --> 00:14:08,100
And again, this animation is available only because we set it up in the as player before the animation
247
00:14:08,100 --> 00:14:08,790
source.
248
00:14:09,530 --> 00:14:11,120
And this is all it takes.
249
00:14:11,120 --> 00:14:11,930
We just check.
250
00:14:11,930 --> 00:14:12,890
Are we shooting?
251
00:14:12,890 --> 00:14:14,660
If we are shooting, play the idol shoot.
252
00:14:14,660 --> 00:14:16,130
If we're not shooting, play the idol.
253
00:14:16,130 --> 00:14:17,300
Very simple.
254
00:14:17,300 --> 00:14:20,540
And just compile and save to show this off.
255
00:14:21,290 --> 00:14:25,820
And I press J to shoot and you can see we go into the shoot animation.
256
00:14:25,820 --> 00:14:30,410
There still is no shoot animation for the jumping and walking, so we just go back to the regular one.
257
00:14:30,410 --> 00:14:34,970
But if we just stand still again, you can see the shoot animation is playing and we just have to repeat
258
00:14:34,970 --> 00:14:37,490
the same step for all of the other animations now.
259
00:14:37,940 --> 00:14:45,230
So back in the app player, we just want to get all of this and hit control C to copy.
260
00:14:45,230 --> 00:14:49,070
We can go back out to locomotion and let's start from run.
261
00:14:49,070 --> 00:14:52,130
And in here again we can drag this off to the side.
262
00:14:52,130 --> 00:14:57,320
Control V to copy control V to paste this in connect this here.
263
00:14:57,320 --> 00:15:01,520
And again if we are not shooting we just want to play the run.
264
00:15:01,520 --> 00:15:04,970
If we are shooting then play run shoot.
265
00:15:06,020 --> 00:15:07,730
And the same thing is going to apply here.
266
00:15:07,730 --> 00:15:14,060
And we go back, do the same for jump rise again, drag it off, control V to paste it in.
267
00:15:14,060 --> 00:15:14,720
Again.
268
00:15:14,720 --> 00:15:16,040
We are not shooting.
269
00:15:16,040 --> 00:15:17,420
Just play jump rise.
270
00:15:17,420 --> 00:15:19,610
If we are shooting, jump.
271
00:15:19,610 --> 00:15:20,810
Rise shoot.
272
00:15:21,510 --> 00:15:22,440
Like this.
273
00:15:24,450 --> 00:15:26,910
And lastly, do the same thing for fall.
274
00:15:27,060 --> 00:15:28,260
Drag this off here.
275
00:15:28,680 --> 00:15:30,600
Again connect this here.
276
00:15:30,600 --> 00:15:32,280
We are not shooting.
277
00:15:32,280 --> 00:15:35,640
So false is just fall and then play fall.
278
00:15:35,640 --> 00:15:36,630
Shoot.
279
00:15:37,300 --> 00:15:38,440
Just like this.
280
00:15:39,060 --> 00:15:39,840
Very simple.
281
00:15:39,840 --> 00:15:42,060
It's just the same pattern we use over and over again.
282
00:15:42,060 --> 00:15:45,630
We can compile, save and that and then test this out.
283
00:15:45,630 --> 00:15:49,710
Display I press shoot, I go into the shoot idle.
284
00:15:49,710 --> 00:15:55,710
If I walk I go into the shoot walking and I jump, I fall and we just seamlessly transition between
285
00:15:55,710 --> 00:15:56,640
all of these.
286
00:15:56,640 --> 00:16:03,690
But now the shooting is just always active, so we need to set back the shooting state after a while
287
00:16:03,690 --> 00:16:04,710
after shooting.
288
00:16:05,160 --> 00:16:10,620
So what we can do now is to after we spawn the projectile, we can just add a delay.
289
00:16:11,290 --> 00:16:15,190
And you can see that there is a delay and a retrigger delay.
290
00:16:15,190 --> 00:16:17,770
And we actually want to use the retrigger delay.
291
00:16:17,770 --> 00:16:21,460
But I want to show you why the regular delay is a bad choice here.
292
00:16:21,820 --> 00:16:28,030
So we can just go here and say after 0.4 seconds, which is just the value I found while prototyping.
293
00:16:28,030 --> 00:16:30,460
I was just trying out different ones and seeing how it feels.
294
00:16:30,970 --> 00:16:37,720
We can then just copy this one control C, control V, and make sure to take off the check mark to set
295
00:16:37,720 --> 00:16:38,800
this to false.
296
00:16:38,800 --> 00:16:39,400
Right.
297
00:16:39,400 --> 00:16:40,240
So we shoot.
298
00:16:40,240 --> 00:16:44,410
And then after 0.4 seconds we just set the is shooting back to false.
299
00:16:44,410 --> 00:16:46,090
And we can just compile and save.
300
00:16:46,540 --> 00:16:48,760
Like this I should one time only.
301
00:16:49,760 --> 00:16:53,390
We go on to the animation and we go back, right?
302
00:16:53,570 --> 00:16:54,890
So this is working.
303
00:16:54,890 --> 00:16:56,450
This is working just fine.
304
00:16:56,450 --> 00:16:59,240
But what happens if I press the button twice?
305
00:17:00,680 --> 00:17:06,170
So the second animation just kind of stops almost instantly, right?
306
00:17:06,589 --> 00:17:09,890
Because what happens here is that I press the button once.
307
00:17:10,849 --> 00:17:14,630
And all of this executes and the delay starts.
308
00:17:15,569 --> 00:17:20,730
And if the delay starts, this means that after 0.4 seconds, we're just going to set this back to shooting.
309
00:17:20,730 --> 00:17:25,710
So what happens then is let's say after 0.3 seconds I hit shooting again.
310
00:17:25,710 --> 00:17:29,160
We just execute all of this again and we start the delay again.
311
00:17:29,160 --> 00:17:30,990
But the first delay is still active.
312
00:17:30,990 --> 00:17:34,320
So even after just 0.1 seconds we set it back.
313
00:17:34,320 --> 00:17:36,990
And the second animation is very short.
314
00:17:36,990 --> 00:17:42,360
So what we can do here is to just use a retrigger double delay instead.
315
00:17:42,990 --> 00:17:44,520
And get rid of this one.
316
00:17:45,180 --> 00:17:49,800
And just use this one instead and set this to 0.4.
317
00:17:50,310 --> 00:17:53,310
And we can just compile and save and try this out.
318
00:17:53,310 --> 00:17:56,160
And now again I try to shoot pretty late.
319
00:17:57,020 --> 00:18:00,560
But you see, the animation doesn't reset quickly.
320
00:18:00,980 --> 00:18:02,900
It's always the same amount of time.
321
00:18:02,900 --> 00:18:05,960
And this is what a retrigger delay is great for.
322
00:18:05,990 --> 00:18:12,320
All this does is that if we already have an active delay, but we call this again, the first delay
323
00:18:12,320 --> 00:18:17,480
will just be thrown out and forgotten about and this just becomes the new value we use.
324
00:18:17,660 --> 00:18:22,040
So you always got to be careful with delay and retrigger delay and see which one makes sense.
325
00:18:22,040 --> 00:18:25,070
In this case, retrigger delay is the right choice.
326
00:18:25,100 --> 00:18:28,910
Now we just want to change this duration to a variable so we can easily change it.
327
00:18:28,940 --> 00:18:32,150
We can just drag off here and promote the variable.
328
00:18:33,080 --> 00:18:36,110
And just call it shoot anim duration.
329
00:18:36,810 --> 00:18:37,830
Like this.
330
00:18:38,190 --> 00:18:40,620
And this just makes it easier to manage, compile and save.
331
00:18:40,620 --> 00:18:43,110
And we can see that the default value is 0.4.
332
00:18:43,110 --> 00:18:47,610
So if we want to change this later, instead of just having to look everywhere for this, we can just
333
00:18:47,610 --> 00:18:50,010
go here and change the value very easily.
334
00:18:50,520 --> 00:18:54,660
Next up, we want to fix the position where the projectile is being spawned.
335
00:18:54,690 --> 00:19:00,060
Now when I shoot, it doesn't look too bad, but you can see it kind of comes out of the middle of our
336
00:19:00,060 --> 00:19:03,450
character instead of where the gun is, where the muzzle of the gun is.
337
00:19:03,450 --> 00:19:08,580
So we want to slightly adjust the position, and this becomes even more apparent if we jump and do other
338
00:19:08,580 --> 00:19:09,480
things like that.
339
00:19:09,480 --> 00:19:13,410
So we just want to slightly adjust the position of the projectile being spawned.
340
00:19:13,860 --> 00:19:16,410
There are multiple choices we have for doing this.
341
00:19:16,410 --> 00:19:21,960
And the first thing that comes to mind, if you know about all the features of paper, 2D is a sprite
342
00:19:21,960 --> 00:19:22,920
socket.
343
00:19:22,920 --> 00:19:25,140
And I'm just going to show you how this works.
344
00:19:25,140 --> 00:19:27,030
So we can go to content draw.
345
00:19:27,030 --> 00:19:32,550
We can go to content paper assets characters and player.
346
00:19:32,550 --> 00:19:33,720
And in the frames.
347
00:19:33,720 --> 00:19:35,340
This is where all of our sprites are.
348
00:19:35,340 --> 00:19:38,400
So we just want to look for a one off the frames that has shooting.
349
00:19:38,400 --> 00:19:38,700
Right.
350
00:19:38,700 --> 00:19:41,430
So this one for example idle shoot zero.
351
00:19:41,430 --> 00:19:42,600
Open it up.
352
00:19:44,580 --> 00:19:47,370
And here on the right side you can see sockets.
353
00:19:47,370 --> 00:19:49,830
So I can just go here and add a socket.
354
00:19:49,830 --> 00:19:52,800
And you can see here socket zero one.
355
00:19:53,190 --> 00:19:59,760
And if we open this up and the transform you can see that we have the location rotation and scale.
356
00:19:59,760 --> 00:20:05,880
So this lets us set a specific position rotation and scale on every single sprite individually.
357
00:20:05,880 --> 00:20:10,860
So we can just drag off here for example and go to the gun like here.
358
00:20:10,860 --> 00:20:12,450
So this is the muzzle of the gun right.
359
00:20:12,450 --> 00:20:15,030
This is where you want the projectile to spawn.
360
00:20:15,730 --> 00:20:19,000
And rotation 000 means that it is facing forward.
361
00:20:19,000 --> 00:20:22,060
So you can see this red arrow which is also correct.
362
00:20:22,060 --> 00:20:22,330
Right.
363
00:20:22,330 --> 00:20:26,080
We want this location and we want this rotation for the bullet to come out of.
364
00:20:26,080 --> 00:20:28,300
So this looks like a good solution.
365
00:20:28,300 --> 00:20:34,450
However sadly this system can be quite buggy sometimes it works out great and I'm using this extensively
366
00:20:34,450 --> 00:20:35,140
in my bitmap.
367
00:20:35,140 --> 00:20:36,520
I didn't have any problems.
368
00:20:36,520 --> 00:20:40,900
However, then I was making another game and then it just didn't work.
369
00:20:40,900 --> 00:20:42,430
So this is actually a solution.
370
00:20:42,430 --> 00:20:44,620
I don't want to recommend too much anymore.
371
00:20:44,620 --> 00:20:49,210
You can try it out for your other games and see if it works, but there can be issues and I just want
372
00:20:49,210 --> 00:20:50,620
you to be aware of this.
373
00:20:50,620 --> 00:20:53,860
So in this case, there's actually another quick solution we can use.
374
00:20:53,860 --> 00:20:56,380
And we're not going to use sockets for this game.
375
00:20:56,890 --> 00:21:00,370
So we can just go back here to the trash and just throw it out.
376
00:21:00,370 --> 00:21:02,380
So we're not gonna have a socket anymore.
377
00:21:02,930 --> 00:21:05,540
And then just save the sprite and go back.
378
00:21:05,540 --> 00:21:09,230
The way we're going to do this is in the BP player.
379
00:21:09,890 --> 00:21:12,500
We can go to the viewport just so we see what's up.
380
00:21:12,500 --> 00:21:18,830
And here on the capsule component we want to add a scene component right.
381
00:21:18,830 --> 00:21:22,370
So utility scene and the scene is just a very simple thing right.
382
00:21:22,370 --> 00:21:26,180
It has a location rotation and scale pretty much like a sprite socket.
383
00:21:26,180 --> 00:21:27,500
So it's something very similar.
384
00:21:27,500 --> 00:21:30,020
And I'm just going to call it shoot pos.
385
00:21:31,090 --> 00:21:33,670
And what we can do here now is the same thing.
386
00:21:33,670 --> 00:21:39,370
We can just drag it around and set it to a certain location that we want to use.
387
00:21:39,370 --> 00:21:42,700
But the problem we have now is that we are playing the idle animation.
388
00:21:42,700 --> 00:21:46,330
So it's very hard for us to see where we actually want to position this.
389
00:21:46,330 --> 00:21:50,470
And I'm going to show you a little trick that we're probably going to use a couple of times.
390
00:21:50,470 --> 00:21:52,300
We can go to the sprite.
391
00:21:52,300 --> 00:21:55,750
And here for the source flipbook we just look for shoot.
392
00:21:57,410 --> 00:22:00,380
And we want the player idol shoot.
393
00:22:00,380 --> 00:22:00,860
Right?
394
00:22:00,860 --> 00:22:03,230
So now we can see the idol animation here.
395
00:22:03,230 --> 00:22:05,600
And this one doesn't have a lot of movement, so it's fine.
396
00:22:05,600 --> 00:22:11,210
But we could also go to play rate and just set this to zero on the correct frame so it doesn't move.
397
00:22:11,210 --> 00:22:15,080
And then we can set our shoot position to where we want it to be.
398
00:22:15,080 --> 00:22:17,120
And we can just drag this over here.
399
00:22:17,820 --> 00:22:18,900
To like 60.
400
00:22:19,170 --> 00:22:20,250
Maybe a little bit more inside.
401
00:22:20,250 --> 00:22:21,240
Yeah, 50.
402
00:22:21,240 --> 00:22:23,310
And this is too big of a jump.
403
00:22:23,310 --> 00:22:25,290
This ten is too big of a jump.
404
00:22:25,290 --> 00:22:30,120
So we can go here and set the snap size to five and go down here.
405
00:22:30,120 --> 00:22:30,300
Right.
406
00:22:30,300 --> 00:22:33,870
So now we're in the middle of the gun I think this is a good location.
407
00:22:33,870 --> 00:22:35,520
If you want to make some small adjustments.
408
00:22:35,520 --> 00:22:37,320
You can also just type in the number right.
409
00:22:37,320 --> 00:22:39,480
You can see that we're not exactly in the middle.
410
00:22:39,480 --> 00:22:42,510
So maybe you can go to four which is even better.
411
00:22:42,510 --> 00:22:45,930
And yeah this is just the position we want to have for shooting.
412
00:22:46,200 --> 00:22:47,760
And this is how we set it up.
413
00:22:47,760 --> 00:22:53,280
So now we can just go back to the sprite, make sure to set the play rate back to one and also just
414
00:22:53,280 --> 00:22:56,670
play the idle animation again player.
415
00:22:57,690 --> 00:22:58,920
Play your idol.
416
00:23:00,270 --> 00:23:02,040
Right, so everything is back to normal.
417
00:23:02,040 --> 00:23:07,470
But now we have our shoot position here, which we can use in our blueprints to determine where the
418
00:23:07,470 --> 00:23:08,940
projectile is being spawned.
419
00:23:09,270 --> 00:23:14,280
So back in the event graph, we want to go to our IA shoot.
420
00:23:14,280 --> 00:23:20,100
And here, instead of using the Get Actor location for where we spawn the projectile and the rotation,
421
00:23:20,100 --> 00:23:22,290
we want to get this from the shoot position.
422
00:23:22,290 --> 00:23:24,240
So we can just delete both of these.
423
00:23:24,240 --> 00:23:31,170
Hit delete on the keyboard, can grab out the shoot position and here we want to get world location.
424
00:23:32,480 --> 00:23:33,260
Like this.
425
00:23:34,240 --> 00:23:41,440
I just use this for the spawn transform location and we want to get world rotation as well.
426
00:23:42,200 --> 00:23:44,150
And connect this here again scale.
427
00:23:44,150 --> 00:23:45,410
We just want to keep one.
428
00:23:45,410 --> 00:23:48,350
We don't want to mess with this and this is all we need.
429
00:23:48,350 --> 00:23:54,590
Now we know where the scene component is in the world and we tell that to the projectile we spawn.
430
00:23:54,680 --> 00:23:57,050
And we can just compile and save and go here.
431
00:23:58,270 --> 00:23:59,650
And now when I shoot.
432
00:24:00,130 --> 00:24:04,420
You can see that the bullet spawns a little bit in front of us like this.
433
00:24:04,900 --> 00:24:07,210
And you can see it also looks fine if we walk.
434
00:24:07,210 --> 00:24:12,490
It also looks fine if we jump so gladly we don't have to prepare a different position for each one of
435
00:24:12,490 --> 00:24:13,630
these animations.
436
00:24:13,630 --> 00:24:18,250
There is going to be a case later on for the climbing animation, where the position is a little bit
437
00:24:18,250 --> 00:24:21,580
different, and I'm going to show you how we can take care of that case as well.
438
00:24:21,880 --> 00:24:27,070
One problem we still have is that I can just keep on shooting infinitely, and there is no cooldown.
439
00:24:27,070 --> 00:24:31,090
There's no cap on how many bullets I can have, and that is what we're going to take care of in the
440
00:24:31,090 --> 00:24:31,960
next video.
41638
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.