WEBVTT 1 00:00:23.475 --> 00:00:25.725 Hello, my name is Lee Young hoon 2 00:00:25.725 --> 00:00:30.175 In this session, we're going to implement shooting and sniper modes 3 00:00:30.175 --> 00:00:35.525 In this chapter, we will add a grenade launcher and a sniper rifle to the character 4 00:00:35.525 --> 00:00:39.575 We will learn how to implement the functions of each gun 5 00:00:39.575 --> 00:00:44.725 We will also learn how to swap between guns based on user input 6 00:00:44.725 --> 00:00:48.375 And implement a Crosshair using widgets 7 00:00:48.375 --> 00:00:52.325 First, let's place the grenade launcher and sniper rifle 8 00:00:52.325 --> 00:00:56.325 Placement of grenade launcher and sniper rifle 9 00:00:56.325 --> 00:00:59.225 If the player is positioned like this 10 00:00:59.225 --> 00:01:01.775 We will place two guns in front of the player like this 11 00:01:01.775 --> 00:01:05.160 We will place Gun 1 and Gun 2 accordingly 12 00:01:05.160 --> 00:01:07.060 Next, when Gun 1 is fired 13 00:01:07.060 --> 00:01:08.375 This is a regular gun 14 00:01:08.375 --> 00:01:12.075 We will implement the bullets to be fired in a straight line 15 00:01:12.075 --> 00:01:13.574 And then for the Gun 2 16 00:01:13.574 --> 00:01:17.024 Something invisible like a laser will shoot out 17 00:01:17.024 --> 00:01:21.959 And there will be a visual effect VFX of explosion effect 18 00:01:21.959 --> 00:01:25.374 I will demonstrate those elements here 19 00:01:25.374 --> 00:01:29.924 To implement these, we'll also need to add input commands 20 00:01:31.374 --> 00:01:34.374 We'll need input commands for selecting the guns 21 00:01:35.574 --> 00:01:40.879 I'll use the number 1 and 2 on the keyboard for selection 22 00:01:40.879 --> 00:01:44.379 And we'll need to be able to zoom in, right? 23 00:01:45.374 --> 00:01:49.360 For the sniper rifle, it should have zoom functionality 24 00:01:49.360 --> 00:01:52.469 And then for the actual shooting 25 00:01:53.800 --> 00:01:57.300 These kinds of inputs must be made 26 00:01:57.300 --> 00:01:59.174 So, the first things first 27 00:01:59.174 --> 00:02:02.324 Let's place the guns first 28 00:02:03.239 --> 00:02:06.289 Launch Unreal Engine to start off 29 00:02:11.399 --> 00:02:14.474 I've prepared some files 30 00:02:14.474 --> 00:02:16.700 These two files here 31 00:02:19.827 --> 00:02:22.674 I'll create a folder named Models 32 00:02:22.674 --> 00:02:27.100 And copy those assets into it 33 00:02:29.273 --> 00:02:33.273 I'll create a folder named Models using Unreal Editor 34 00:02:33.273 --> 00:02:36.319 And open the Content folder 35 00:02:36.919 --> 00:02:41.419 I'll copy them over here 36 00:02:49.274 --> 00:02:50.474 I've copied them like this 37 00:02:50.474 --> 00:02:53.474 Then the program will ask you if you want to import them 38 00:02:53.474 --> 00:02:56.600 Let's click import 39 00:02:56.600 --> 00:03:01.624 If you click Import All button you will see that everything's been implemented well 40 00:03:07.090 --> 00:03:12.624 Then, you can find SniperGun and FPWeapon here 41 00:03:12.624 --> 00:03:13.974 Select these two 42 00:03:13.974 --> 00:03:16.174 And move them to Models folder 43 00:03:16.174 --> 00:03:20.374 Drag and drop and select Move Here option 44 00:03:20.374 --> 00:03:26.024 And I'll move the SniperGun to Models by selecting Move Here 45 00:03:26.024 --> 00:03:28.424 And in Models, if you take a look 46 00:03:28.424 --> 00:03:31.880 SniperGun looks like this, but now that I think about it 47 00:03:31.880 --> 00:03:37.580 We are missing Material, let's fill it up by sliding up 48 00:03:41.873 --> 00:03:48.223 Here are two types, diffuse and normal color 49 00:03:48.223 --> 00:03:50.223 Put the diffuse map into this one 50 00:03:50.223 --> 00:03:53.773 And I'll insert the normal here 51 00:04:00.573 --> 00:04:06.523 By doing so, you can see that the texture fits well 52 00:04:10.823 --> 00:04:15.523 The gun is well made, you can see the colors are applied nicely like this 53 00:04:15.523 --> 00:04:18.920 This is a gun that originally comes with the Unreal Engine as an example 54 00:04:18.920 --> 00:04:21.620 We'll be using this one 55 00:04:23.373 --> 00:04:28.399 The regular gun is set as a Skeletal Mesh 56 00:04:28.399 --> 00:04:33.799 And for something like the SniperGun, it's set as a Static Mesh 57 00:04:33.799 --> 00:04:36.499 So, we'll be implementing these 58 00:04:38.839 --> 00:04:44.399 Let's move to the player's header file 59 00:04:44.399 --> 00:04:47.249 Let's start off at the bottom 60 00:04:49.569 --> 00:04:53.349 We want the Gun here, so I will write UPROPERTY 61 00:04:58.273 --> 00:05:03.273 And EditAnywhere and have the class be as Skeletal Mesh 62 00:05:03.273 --> 00:05:06.790 And then USkeletalMeshComponent 63 00:05:12.623 --> 00:05:18.423 Here, let's have this as GunMesh 64 00:05:18.423 --> 00:05:22.659 Copy them all up and make one for Static Mesh 65 00:05:24.973 --> 00:05:30.110 Let's name it the SniperMesh 66 00:05:33.880 --> 00:05:39.129 Let's proceed to implement this now, move to the constructor 67 00:05:40.923 --> 00:05:46.649 And continue writing at the bottom 68 00:05:50.173 --> 00:05:51.623 We already have what we want over here 69 00:05:51.623 --> 00:05:56.040 Copy and paste to save time 70 00:05:56.040 --> 00:05:59.823 This one was USkeletalMesh 71 00:05:59.823 --> 00:06:03.200 I mean USkeletalMeshComponent not just Mesh 72 00:06:03.200 --> 00:06:04.850 Write one up like this 73 00:06:04.850 --> 00:06:11.872 And then the same goes with the sniper 74 00:06:12.572 --> 00:06:20.672 Write this one with UStaticMeshComponent 75 00:06:20.672 --> 00:06:26.920 Both Mesh are going to be attached to GetMesh 76 00:06:26.920 --> 00:06:36.170 So GetMesh will be SetupAttachment 77 00:06:37.872 --> 00:06:41.572 And then GetMesh 78 00:06:50.422 --> 00:06:54.079 The same goes for this one as well 79 00:06:56.672 --> 00:06:59.722 Since for these objects, we won't be using collision object 80 00:06:59.722 --> 00:07:12.822 So, let's use SetCollisionProfileNAme 81 00:07:12.822 --> 00:07:19.772 And add NoCollision 82 00:07:19.772 --> 00:07:22.622 Also do the same for SniperMesh 83 00:07:24.822 --> 00:07:28.772 After adding that, we have to 84 00:07:28.772 --> 00:07:31.519 Connect the Meshes to assets 85 00:07:31.519 --> 00:07:34.522 Up here, we've done this 86 00:07:34.522 --> 00:07:37.272 We used FObjectFinder to handle these 87 00:07:37.272 --> 00:07:41.772 We will use the same method for these ones 88 00:07:41.772 --> 00:07:47.522 At the bottom, copy and paste and this one should be TempGunMesh 89 00:07:47.522 --> 00:07:52.239 Make sure you name them right 90 00:07:52.239 --> 00:07:54.372 This one still will be SkeletalMesh 91 00:07:54.372 --> 00:07:56.539 Seems like this should be good 92 00:07:56.539 --> 00:08:00.109 The actual implementation will be for this one, not that one 93 00:08:01.720 --> 00:08:06.522 Write like this and will attach them for now 94 00:08:06.522 --> 00:08:08.959 We'll come back to review the content here later 95 00:08:08.959 --> 00:08:14.249 And I'll just copy them and for the SniperMesh 96 00:08:15.839 --> 00:08:22.572 We will use StaticMesh instead of Skeletal 97 00:08:22.572 --> 00:08:28.572 Let's change this Temp to Sniper as well 98 00:08:28.572 --> 00:08:34.719 That's that and this one should be UStaticMesh 99 00:08:34.719 --> 00:08:38.800 I'll change it like this and replace all the names 100 00:08:40.479 --> 00:08:42.621 Load everything like this 101 00:08:42.621 --> 00:08:51.521 Now let's find the path 102 00:08:52.071 --> 00:08:55.340 Right here 103 00:08:56.559 --> 00:09:01.209 Right click with your mouth 104 00:09:01.209 --> 00:09:04.479 Just use Ctrl and C as a short cut 105 00:09:04.479 --> 00:09:07.821 So you can use that to copy 106 00:09:07.821 --> 00:09:12.359 Sniper goes to the bottom one, so paste it there 107 00:09:12.359 --> 00:09:15.459 Let's do the same for the top one with GunMesh 108 00:09:15.459 --> 00:09:22.200 GunMesh is right here, so copy it with Ctrl and C 109 00:09:22.200 --> 00:09:25.071 Or you can just copy the Reference here 110 00:09:25.771 --> 00:09:28.140 And come over here to add it there 111 00:09:30.900 --> 00:09:34.621 And make sure to change 112 00:09:34.621 --> 00:09:39.080 TempMesh to TempGunMesh 113 00:09:39.080 --> 00:09:44.571 And turn off Unreal Engine to try compiling again 114 00:09:47.400 --> 00:09:49.150 And then run it again 115 00:09:52.271 --> 00:09:56.571 I'm going to adjust the size and position of GunMesh and SniperMesh slightly 116 00:09:56.571 --> 00:10:01.971 Let's go to player and try adjusting 117 00:10:01.971 --> 00:10:08.640 After locking this, make small size adjustment like by 0.125 118 00:10:08.640 --> 00:10:11.421 And the position as well 119 00:10:11.421 --> 00:10:18.921 Let's move it up a bit, and same for GunMesh as well 120 00:10:18.921 --> 00:10:23.121 Alright, let's set it like this 121 00:10:25.321 --> 00:10:28.571 Compile and run it 122 00:10:28.571 --> 00:10:31.119 We can see it working well 123 00:10:32.769 --> 00:10:35.930 In order to handle input 124 00:10:40.171 --> 00:10:44.671 Let's add four inputs, concepts of selection 125 00:10:44.671 --> 00:10:48.171 Zoom and shooting 126 00:10:48.171 --> 00:10:51.671 If you look here, go to Input and select Input Action 127 00:10:51.671 --> 00:11:01.271 Make IA_TPSChooseGun 128 00:11:02.920 --> 00:11:08.479 Let's copy this and name it Choosesniper 129 00:11:10.220 --> 00:11:12.370 Copy it 130 00:11:15.270 --> 00:11:22.120 Name it Zoom and copy another to name it Fire 131 00:11:22.120 --> 00:11:26.420 I created total of four inputs 132 00:11:26.420 --> 00:11:29.070 They are all type bool 133 00:11:29.970 --> 00:11:32.950 Let's register it here 134 00:11:34.200 --> 00:11:36.550 Let's do it one by one 135 00:11:37.420 --> 00:11:44.709 ChooseFire, it's my mistake, it's supposed to be ChooseGun 136 00:11:45.420 --> 00:11:52.220 Should be just Fire 137 00:11:52.220 --> 00:11:56.080 I'll set Fire input as left mouse button 138 00:11:56.080 --> 00:12:04.820 And then add, ChooseGun and Sniper 139 00:12:04.820 --> 00:12:15.620 I'll have ChooseGun as number 1, and 2 for Choose Sniper 140 00:12:15.620 --> 00:12:20.670 Zoom should be right click button 141 00:12:20.670 --> 00:12:24.370 We want right click press to process Zoom In 142 00:12:24.370 --> 00:12:27.820 And releasing to process Zoom Out 143 00:12:27.820 --> 00:12:31.020 Now let's switch the name, Zoom 144 00:12:34.870 --> 00:12:39.000 Change ChooseZoom into Zoom 145 00:12:39.000 --> 00:12:43.019 So, place it like here 146 00:12:43.019 --> 00:12:47.720 Go to the main character and in the TPS player header 147 00:12:47.720 --> 00:12:50.459 Register all those keys 148 00:12:53.409 --> 00:12:55.770 Add one, two, three, four 149 00:12:55.770 --> 00:13:01.170 So, here should have ChooseGun 150 00:13:02.670 --> 00:13:04.620 Since it's Choose something 151 00:13:04.620 --> 00:13:10.470 So, let's make it simple and name it just Gun and Sniper 152 00:13:10.470 --> 00:13:15.570 And this one will be Zoom and Finally, Fire 153 00:13:15.570 --> 00:13:18.270 So, we've added four 154 00:13:20.359 --> 00:13:24.619 Now, we need to make a input function 155 00:13:24.619 --> 00:13:34.479 With these, Gun and Sniper 156 00:13:34.479 --> 00:13:38.079 This one is Woom in and Lout 157 00:13:38.079 --> 00:13:43.359 Let's make two and put Fire 158 00:13:43.359 --> 00:13:49.269 I'll register all these functions first and then proceed with the implementation 159 00:13:54.319 --> 00:14:00.219 Let's go to the source file and register those functions 160 00:14:00.219 --> 00:14:07.919 Copy Jump and with other new makes it five 161 00:14:15.219 --> 00:14:31.619 Gun, Sniper, ZoomIn, ZoomOut, and Fire functions are available 162 00:14:31.619 --> 00:14:34.719 Do the same thing 163 00:14:34.719 --> 00:14:38.819 Press Alt to get a hold of this block here 164 00:14:39.919 --> 00:14:48.919 Gun, Snipper, Zoom, these are both zoom 165 00:14:50.350 --> 00:14:56.919 Zoom will be changed to Started and Completed 166 00:14:56.919 --> 00:15:01.919 This should be arranged under Fire 167 00:15:01.919 --> 00:15:04.019 The other actions trigger upon pressing, 168 00:15:04.019 --> 00:15:07.919 And For, ZoomIn and lout will p 169 00:15:07.919 --> 00:15:11.919 Implementing gun swapping and crosshair functionality 170 00:15:11.919 --> 00:15:14.919 Now then, let's start by implementing gun swapping 171 00:15:14.919 --> 00:15:19.880 So, now that these functions are implemented, we'll handle the processing here 172 00:15:19.880 --> 00:15:23.219 Then, Remember which gun we are currently wielding 173 00:15:23.219 --> 00:15:25.919 You'll need to remember which gun you're currently wielding 174 00:15:25.919 --> 00:15:28.719 Like when you ZoomIn while firing 175 00:15:28.719 --> 00:15:30.719 Then you'll need to branch at that point as well 176 00:15:30.719 --> 00:15:33.869 When we have the sniper instead of the default gun 177 00:15:33.869 --> 00:15:37.239 We'll need to fire bullets differently 178 00:15:37.239 --> 00:15:43.469 We'll create a variable here to facilitate branching 179 00:15:43.469 --> 00:15:46.119 Here, write bool 180 00:15:46.119 --> 00:15:52.840 And bChooseGunSniperGun 181 00:15:54.918 --> 00:15:59.768 Initially set it to false to indicate starting with the default gun 182 00:15:59.768 --> 00:16:04.718 Now, let's go back and try one by one 183 00:16:04.718 --> 00:16:09.020 When having Gun, it should be false 184 00:16:11.020 --> 00:16:16.159 Copy it and make it true for sniper 185 00:16:16.159 --> 00:16:19.518 And each time you select this 186 00:16:19.518 --> 00:16:22.168 The gun should appear and disappear 187 00:16:22.168 --> 00:16:28.918 When you initially select the Gun, it should appear like this 188 00:16:28.918 --> 00:16:32.018 The regular gun is actually a grenade launcher 189 00:16:32.018 --> 00:16:39.599 The grenade launcher will be visible, and then the sniper rifle won't be 190 00:16:39.599 --> 00:16:42.749 This is how we want to handle it and do the opposite for this 191 00:16:47.218 --> 00:16:53.718 To achieve the visibility toggle between the two components 192 00:16:53.718 --> 00:16:56.118 We are already using it as components 193 00:16:56.668 --> 00:17:00.568 We have GunMeshComponent 194 00:17:00.568 --> 00:17:05.439 To make this visible, you have the SetVisibility function available 195 00:17:05.439 --> 00:17:06.968 You can use this functionality 196 00:17:06.968 --> 00:17:10.068 If you make it true, you'll be able to see it 197 00:17:10.068 --> 00:17:17.920 And then use SetVisibility with false for SniperMesh too 198 00:17:17.920 --> 00:17:19.168 Write it like this 199 00:17:19.168 --> 00:17:29.268 Do the opposite in the bottom, this one to be false and that one to be true 200 00:17:29.268 --> 00:17:32.329 Now wrap it up and compile it one more time 201 00:17:42.368 --> 00:17:48.289 Let's try running it, try number 1,2,1,2 202 00:17:49.439 --> 00:17:51.018 Input doesn't work now 203 00:17:51.018 --> 00:17:55.839 The key assignment part probably hasn't been included here yet 204 00:17:55.839 --> 00:17:59.589 If you look at class default 205 00:17:59.589 --> 00:18:02.760 It's missing, we need to fill it up 206 00:18:02.760 --> 00:18:13.189 In IA Gun, ChooseGun, ChooseSniper and Zoom and then fire 207 00:18:15.160 --> 00:18:17.789 Fill all of them up 208 00:18:19.520 --> 00:18:22.717 Now, press 1 and 2, you can see them swapping 209 00:18:22.717 --> 00:18:26.867 It seems like we need to start in this state at the beginning 210 00:18:26.867 --> 00:18:29.267 Let's handle that too 211 00:18:29.267 --> 00:18:33.917 It will work if we call 212 00:18:33.917 --> 00:18:36.129 OnIAGun at BeginPlay 213 00:18:36.129 --> 00:18:38.267 So, we are going to call it 214 00:18:38.267 --> 00:18:45.619 Go in the top and call in BeginPlay 215 00:18:45.619 --> 00:18:48.619 When we call it, we need variables 216 00:18:48.619 --> 00:18:55.917 Alright, so let's create an FInputActionValue and set it up 217 00:18:57.417 --> 00:19:04.810 To make it appear as the default gun when initialized 218 00:19:05.960 --> 00:19:07.717 That's why we did this 219 00:19:08.717 --> 00:19:15.417 And when handling this, we'll also work on the UI 220 00:19:15.417 --> 00:19:18.417 Structure like this 221 00:19:19.217 --> 00:19:22.917 you'll see the default gun first, followed by the sniper rifle 222 00:19:22.917 --> 00:19:28.160 Then, you have a UI named Crosshair designed like this 223 00:19:28.160 --> 00:19:31.960 Then, there's a Sniperscope image that fills the screen 224 00:19:31.960 --> 00:19:35.719 With a hole in the middle for aiming 225 00:19:35.719 --> 00:19:38.467 Let me show you this 226 00:19:38.467 --> 00:19:42.317 If you look at this model, SniperGun 227 00:19:42.317 --> 00:19:48.717 This is Crosshair and the image I've talked about 228 00:19:48.717 --> 00:19:53.017 I would like to make it an UI to control it 229 00:19:53.617 --> 00:19:56.267 So, you want both UI elements to be invisible 230 00:19:56.267 --> 00:20:00.570 when using the default gun and visible when using the sniper rifle 231 00:20:00.570 --> 00:20:04.067 Let's say this is the Crosshair and this to be Sniper 232 00:20:04.067 --> 00:20:06.117 If we were to name it like this 233 00:20:06.117 --> 00:20:12.017 And if ZoomIn when using Sniper rifle 234 00:20:12.017 --> 00:20:15.280 You can see the S and then the Sniper 235 00:20:15.280 --> 00:20:21.867 And whem ,Zoomout, have the default Crosshair 236 00:20:21.867 --> 00:20:23.199 This is how we handle it 237 00:20:23.199 --> 00:20:27.117 And when holding a default gun, Both won't be visible 238 00:20:27.117 --> 00:20:28.267 Let's handle that like that 239 00:20:28.267 --> 00:20:32.000 The reason is that default gun shoots in front of the barrle 240 00:20:32.000 --> 00:20:36.066 But for sniper, we shoot align to the camera's front view 241 00:20:36.066 --> 00:20:38.816 You'll be aiming at the center of the screen 242 00:20:38.816 --> 00:20:44.466 So, we'll display this UI only when using the sniper rifle 243 00:20:44.466 --> 00:20:48.479 I should create the UI, then. Let's head to the Blueprint folder 244 00:20:48.479 --> 00:20:53.466 Here, let's create two widget blueprints as User Interfaces 245 00:20:53.466 --> 00:21:00.016 I'll name it WBP Crosshair. 246 00:21:01.316 --> 00:21:06.766 Back in the old days without scopes 247 00:21:06.766 --> 00:21:10.560 They used human hair to improvise shooting guns 248 00:21:10.560 --> 00:21:14.266 That's where the term crosshair comes from 249 00:21:14.616 --> 00:21:20.959 I'll duplicate this one, and name it WBP Sniper 250 00:21:21.959 --> 00:21:26.416 Like this, we made two UIs and it needs to be filled up 251 00:21:26.416 --> 00:21:31.366 Here, let's make canvas for now 252 00:21:31.666 --> 00:21:34.466 And I will insert an image 253 00:21:34.466 --> 00:21:40.959 0If you search here you'll find Crosshair it here 254 00:21:40.959 --> 00:21:42.766 Add it like this 255 00:21:42.766 --> 00:21:45.666 I want it as a sqaure 256 00:21:45.666 --> 00:21:48.916 Center it with an anchor 257 00:21:48.916 --> 00:21:55.710 And then 0.5 and about 200 258 00:21:58.016 --> 00:22:02.516 200 might be a bit much, let's do 150 259 00:22:02.516 --> 00:22:05.670 Let's put it here and then 0,0 should be fine 260 00:22:07.216 --> 00:22:10.866 Let's change the color to red or something 261 00:22:12.266 --> 00:22:15.040 Similar to give it this kind of look 262 00:22:18.100 --> 00:22:23.079 Compile this, and then I'll try the sniper one next 263 00:22:23.079 --> 00:22:27.566 Same way, canvas then, insert images 264 00:22:27.566 --> 00:22:31.216 And I want to insert the images at their original sizes 265 00:22:31.216 --> 00:22:33.616 Positioning in the center is the same 266 00:22:33.616 --> 00:22:35.816 Centered it 267 00:22:36.716 --> 00:22:40.680 And then place at 0.5, 0.5 268 00:22:40.680 --> 00:22:45.066 Then you'll see Sniperscope here 269 00:22:45.066 --> 00:22:46.866 You can put that in 270 00:22:46.866 --> 00:22:51.239 It's really small but if you double click it 271 00:22:51.239 --> 00:22:56.366 The real size is 3364X2342 272 00:22:56.366 --> 00:22:59.916 I'll insert them as 3364 x 2343 pixels 273 00:23:00.880 --> 00:23:07.180 I'll input it as 3364 by 2343 pixels here 274 00:23:10.760 --> 00:23:13.960 So now compile it and save 275 00:23:15.199 --> 00:23:19.715 Then, we've prepared who kinds of UI 276 00:23:19.715 --> 00:23:24.640 Let's have the player run the UI and control it 277 00:23:24.640 --> 00:23:28.440 Then it goes to the player's header 278 00:23:28.440 --> 00:23:39.465 Now we have to prepare UPROPERTY EditAnywhere in the UI 279 00:23:39.465 --> 00:23:42.565 Bring this TSubcalssOf 280 00:23:42.565 --> 00:23:49.280 That is UserWidget attach it to class 281 00:23:49.280 --> 00:23:59.319 And here, CrosshairUIFactory 282 00:23:59.319 --> 00:24:01.439 And then make another 283 00:24:01.439 --> 00:24:04.265 Do the same for the sniper 284 00:24:04.265 --> 00:24:08.599 Here, SniperUIFactory 285 00:24:08.599 --> 00:24:13.015 And then UUserWidget keep what we actually made 286 00:24:13.015 --> 00:24:15.715 This one is used to create 287 00:24:15.715 --> 00:24:18.065 And having actual thing 288 00:24:18.065 --> 00:24:21.199 Control visibility 289 00:24:21.199 --> 00:24:24.115 We also use UPROPERTY here 290 00:24:24.115 --> 00:24:28.400 I won't place indicator here 291 00:24:28.400 --> 00:24:34.065 And then write class UUserWidget 292 00:24:34.065 --> 00:24:40.160 Write CrosshairUI 293 00:24:40.160 --> 00:24:44.689 Make one more and name it SniperUI 294 00:24:50.965 --> 00:24:54.565 We will have it BeginPlay initially as we enter 295 00:24:54.565 --> 00:24:58.059 We will let it load there 296 00:24:59.359 --> 00:25:04.615 Let's go to BeginPlay in the source file 297 00:25:04.615 --> 00:25:09.365 Since we have to control the UI here 298 00:25:09.365 --> 00:25:16.415 create and remember the widget in the upper part 299 00:25:16.415 --> 00:25:24.865 Those will be Crosshair and Sniper 300 00:25:24.865 --> 00:25:28.565 They will be creating and remembering two widgets 301 00:25:28.565 --> 00:25:35.314 write CreateWidget 302 00:25:35.314 --> 00:25:39.314 If you look here, there is OwningObject 303 00:25:39.314 --> 00:25:42.564 Usually, insert World, write GetWorld 304 00:25:43.714 --> 00:25:46.114 And next, insert Factory 305 00:25:46.114 --> 00:25:50.664 And then add CrosshairUIFactory 306 00:25:50.664 --> 00:25:53.759 Then you'll need to add the header to receive this 307 00:25:53.759 --> 00:25:58.214 You'll need to add the header for "UserWidget" to achieve this 308 00:25:58.214 --> 00:26:00.920 Like so 309 00:26:00.920 --> 00:26:03.564 For you to take a look 310 00:26:03.564 --> 00:26:06.764 Let's see if it goes into the upper part 311 00:26:06.764 --> 00:26:08.699 Then they are all added 312 00:26:10.640 --> 00:26:17.464 To create a UserWidget and handle showing and hiding it specifically 313 00:26:17.464 --> 00:26:20.800 In order to change visibility 314 00:26:20.800 --> 00:26:25.714 We need to register and use the UMG module 315 00:26:25.714 --> 00:26:27.920 So, let's add this one, too 316 00:26:27.920 --> 00:26:33.114 We are going to add a module, so go to Build.cs file 317 00:26:33.114 --> 00:26:36.314 Add EnhancedInput 318 00:26:36.314 --> 00:26:41.114 And then add UMG on the side here 319 00:26:41.114 --> 00:26:45.319 You need to add a module in order to use it 320 00:26:45.319 --> 00:26:47.564 Now let's go back 321 00:26:48.114 --> 00:26:55.239 Now, place these in CrosshairUI 322 00:26:55.239 --> 00:26:57.189 And make another just like we've been doing 323 00:26:57.189 --> 00:27:05.060 This one will be placed in SniperUI and here SniperUIFactory 324 00:27:14.610 --> 00:27:18.920 And with default gun, both UI will be made invisible 325 00:27:18.920 --> 00:27:23.864 So, in here, we need to make it invisible 326 00:27:23.864 --> 00:27:29.064 We will go here and handle it, OnIAGun I mean 327 00:27:29.064 --> 00:27:32.514 We did these things to hide Grenade launcher 328 00:27:32.514 --> 00:27:35.160 Let's handle it here together 329 00:27:35.160 --> 00:27:41.914 CrosshairUI has Setvisibility here too 330 00:27:41.914 --> 00:27:46.680 But here, the argument passed as a parameter is slightly different 331 00:27:46.680 --> 00:27:51.863 We'll name it Hidden since we're going to hide it here 332 00:27:51.863 --> 00:27:54.763 Duplicate another and name it Sniper 333 00:27:56.063 --> 00:27:59.160 This one also will become hidden 334 00:27:59.160 --> 00:28:05.480 I also want to hide this UI 335 00:28:10.363 --> 00:28:15.313 And further down, there's something called Zoom 336 00:28:15.313 --> 00:28:17.079 We have this Sniper as well here 337 00:28:17.079 --> 00:28:23.213 Similarly, We need to add content related to the UI here as well 338 00:28:23.213 --> 00:28:25.520 Therefore, we will do the same here 339 00:28:25.520 --> 00:28:30.513 If you've selected Sniper, then instead of hiding the UI 340 00:28:32.013 --> 00:28:39.763 We want only the Crosshair UI to be visible, like this 341 00:28:39.763 --> 00:28:43.880 Then Crosshair will not be Hidden 342 00:28:43.880 --> 00:28:46.260 But visible 343 00:28:49.463 --> 00:28:53.213 And below here, when you zoom, it'll be different again 344 00:28:53.213 --> 00:28:57.640 When ZoomOut, the crosshair is visible 345 00:28:57.640 --> 00:29:03.813 On the other hand, when it's ZoomIn, we will be able to see sniper only 346 00:29:03.813 --> 00:29:06.280 It will become like this and there will be changes here 347 00:29:06.280 --> 00:29:11.889 This becomes Hidden and do the opposite 348 00:29:15.830 --> 00:29:20.863 However, Zoom should only function when we're 349 00:29:20.863 --> 00:29:22.763 holding the SniperGun 350 00:29:22.763 --> 00:29:25.113 It shouldn't work like this when using a regular gun 351 00:29:25.113 --> 00:29:32.800 So, here we'll use a conditional statement if bChooseSniperGun is true 352 00:29:32.800 --> 00:29:38.600 If this one is false here, we will have it returned 353 00:29:38.600 --> 00:29:43.239 Here as well, you can just do it the same way 354 00:29:46.212 --> 00:29:49.213 And for Zoom, we need to adjust 355 00:29:49.213 --> 00:29:51.280 If you look here, there's a camera 356 00:29:51.280 --> 00:29:54.680 We gave our character a camera component 357 00:29:54.680 --> 00:30:02.319 There is something called the Field Of View 358 00:30:02.319 --> 00:30:04.863 It means what it means 359 00:30:04.863 --> 00:30:09.199 People can typically see about 90 degrees with one eye 360 00:30:09.199 --> 00:30:13.013 So, if you hold your finger to the side 361 00:30:13.013 --> 00:30:14.813 You can still see the finger a little bit 362 00:30:14.813 --> 00:30:18.263 So, generally, it's considered that one eye 363 00:30:18.263 --> 00:30:19.862 Has a field of view of about 90 degrees 364 00:30:19.862 --> 00:30:23.762 Therefore, It is said that with both eyes 365 00:30:23.762 --> 00:30:25.959 We can see a total of approximately 180 degrees 366 00:30:27.509 --> 00:30:29.662 So we use the value of 90 there 367 00:30:29.662 --> 00:30:35.062 since this concerns field of view, a wider FOV means seeing things farther away 368 00:30:35.062 --> 00:30:38.212 While a narrower FOV means seeing things closer 369 00:30:38.212 --> 00:30:42.062 So, if you decrease this value, it zooms in 370 00:30:42.062 --> 00:30:47.012 And if you increase it, it zooms out to see things farther away 371 00:30:47.012 --> 00:30:49.962 So, I'll try to handle this using that information 372 00:30:51.479 --> 00:30:54.612 Then ZoomIn should result in zooming in 373 00:30:55.512 --> 00:30:58.869 Here, we've done this before 374 00:30:59.719 --> 00:31:07.719 We have the camera CamComp, and it has the Field Of View parameter 375 00:31:07.719 --> 00:31:11.619 Let's try value of 20 376 00:31:11.619 --> 00:31:13.812 Try different values yourself and find 377 00:31:13.812 --> 00:31:17.012 The one that works for you 378 00:31:17.012 --> 00:31:19.562 ZoomOut means that your field of view goes back to normal 379 00:31:19.562 --> 00:31:22.740 Since it's default put 90 380 00:31:29.162 --> 00:31:32.759 Now, compile to see the result 381 00:31:43.339 --> 00:31:48.500 I didn't fill up the UI, let's start again 382 00:31:49.512 --> 00:31:54.760 I didn't fill Factory and caused some errors 383 00:32:06.560 --> 00:32:11.800 Open up main character's blueprint class an scroll down 384 00:32:13.162 --> 00:32:19.462 You should be able to find UI Crosshair 385 00:32:19.462 --> 00:32:23.862 Crosshair, and then here, we'll insert Sniper like this 386 00:32:23.862 --> 00:32:27.310 Compile, then run the program 387 00:32:28.412 --> 00:32:30.112 If you press number 2, the gun swaps 388 00:32:30.112 --> 00:32:34.162 mouse right click to zoom in and release to zoom out 389 00:32:34.162 --> 00:32:38.339 However I don't see the UI 390 00:32:42.889 --> 00:32:48.761 Now that I think about it, we just created the UI and didn't attached it to the screen 391 00:32:48.761 --> 00:32:54.061 It exists but not visible 392 00:32:54.061 --> 00:32:56.861 So, let's attach the UI to the screen 393 00:32:56.861 --> 00:33:04.280 Write AddtoViewport in CrosshairUI for it to show up 394 00:33:04.711 --> 00:33:11.850 Same goes for the SniperUI, write AddToViewport 395 00:33:14.560 --> 00:33:17.200 Go back and compile 396 00:33:22.761 --> 00:33:25.811 Run it and press number 2, we see that the UI shows up 397 00:33:25.811 --> 00:33:27.959 Right click for zoom in 398 00:33:27.959 --> 00:33:33.561 Release to zoom out 399 00:33:33.561 --> 00:33:35.211 Now let's try and fire the weapon 400 00:33:35.211 --> 00:33:39.611 Number 1 to fire, Number 2 to see the VFX 401 00:33:39.611 --> 00:33:43.161 Over there with the boom effect 402 00:33:43.161 --> 00:33:47.161 Implementing shotgun and sniper rifle functionalities 403 00:33:47.161 --> 00:33:50.511 Let's work on the default gun first 404 00:33:50.511 --> 00:33:54.079 We need bullets, let's create them 405 00:33:54.079 --> 00:33:59.261 Right click to make blueprint class 406 00:33:59.261 --> 00:34:03.239 Let's begin with C 407 00:34:03.239 --> 00:34:07.011 Choose the actor and come over here 408 00:34:07.011 --> 00:34:10.110 Name it BulletActor 409 00:34:11.159 --> 00:34:13.880 Write BulletActor and then Create 410 00:34:28.511 --> 00:34:29.611 We have our bullet 411 00:34:29.611 --> 00:34:32.479 Let's make the blueprint first 412 00:34:32.479 --> 00:34:38.729 Try BP BulletActor in the blueprint folder 413 00:34:40.339 --> 00:34:42.970 We need to do some coding here 414 00:34:45.161 --> 00:34:46.980 Go to Bullet Actor 415 00:34:49.080 --> 00:34:53.811 We need collision object in the header 416 00:34:53.811 --> 00:34:56.161 Since it will be a bullet, it needs a body 417 00:34:56.161 --> 00:34:58.600 It can be something sphere shaped 418 00:34:58.600 --> 00:35:00.511 And it needs to move 419 00:35:00.511 --> 00:35:04.711 Now, we can use MovementComponent 420 00:35:04.711 --> 00:35:08.260 There is a component for a projectile object 421 00:35:08.260 --> 00:35:12.000 We will utilize that to control this 422 00:35:12.000 --> 00:35:15.490 So, collision object 423 00:35:17.120 --> 00:35:24.510 Appearance, then projectile object 424 00:35:24.510 --> 00:35:32.439 Create these three and write UPROPERTY EditAnywhere 425 00:35:34.010 --> 00:35:40.479 Since it's collision object, Class, let's do sphere shape 426 00:35:40.479 --> 00:35:44.310 We can use USphereComponent 427 00:35:44.310 --> 00:35:47.410 It will provide sphere body 428 00:35:47.410 --> 00:35:54.700 Since it's collision object, let's say CollisionComp 429 00:35:56.840 --> 00:35:59.240 And copy these 430 00:35:59.860 --> 00:36:09.160 To make StaticMeshComponent for handling appearance 431 00:36:09.160 --> 00:36:14.510 Write MeshComp here 432 00:36:15.610 --> 00:36:18.360 Make another and this one is for the projectile object 433 00:36:18.360 --> 00:36:27.460 Write Class and follow it with UProjectileMovementComponent 434 00:36:27.460 --> 00:36:31.220 This is a component 435 00:36:32.479 --> 00:36:40.420 Write MovementComp because this component will handle movement 436 00:36:44.080 --> 00:36:51.079 Let's implement these in the constructor starting with the collision object 437 00:36:53.110 --> 00:36:59.970 Write RootComponent and CreateDefaultSubobject here 438 00:37:09.330 --> 00:37:15.429 Write USphereComponent and TEXT 439 00:37:18.360 --> 00:37:23.110 Will write another one with the same name 440 00:37:23.110 --> 00:37:29.159 This one then, should be SetRootComponent 441 00:37:29.159 --> 00:37:31.389 We will add the header 442 00:37:33.320 --> 00:37:35.609 You guys can do what I did 443 00:37:35.609 --> 00:37:37.709 If you have this program, utilize that 444 00:37:37.709 --> 00:37:40.609 Or I taught you how to find it 445 00:37:40.609 --> 00:37:46.459 You can search it up on google 446 00:37:46.459 --> 00:37:49.600 Therefore, we have the header here 447 00:37:49.600 --> 00:37:54.009 You can copy and paste the whole thing 448 00:37:54.009 --> 00:37:58.309 Anyway, find an easier way for yourselves to do this 449 00:37:58.309 --> 00:38:04.429 We will use this root and MeshComp with copy and paste 450 00:38:06.439 --> 00:38:09.139 Write MeshComponent down 451 00:38:09.139 --> 00:38:12.859 This is a UStaticMeshComponent 452 00:38:17.600 --> 00:38:21.139 Let's attach this one to the Root 453 00:38:22.439 --> 00:38:24.539 SetRootComponent I mean not this 454 00:38:24.539 --> 00:38:30.289 Use SetupAttachment and then RootComponent 455 00:38:32.000 --> 00:38:34.650 And the let's make projectile 456 00:38:34.650 --> 00:38:41.909 MovementComp is CreateDefaultSubobject 457 00:38:41.909 --> 00:38:45.909 Write Movecomponent, no it should be Projectile 458 00:38:45.909 --> 00:38:52.509 Write UProjectileMovementComponent here 459 00:38:52.509 --> 00:38:54.909 You will also need the name like this 460 00:38:58.209 --> 00:39:03.209 I will keep it exactly the same as the variable name 461 00:39:03.209 --> 00:39:06.459 But this doesn't have SetupAttachment 462 00:39:06.459 --> 00:39:09.959 If you look here, there's no SetupAttachment 463 00:39:09.959 --> 00:39:12.760 This only got like UpdatedComponents 464 00:39:12.760 --> 00:39:18.690 Because If you go up to ProjectileMovementComponent 465 00:39:22.409 --> 00:39:26.709 This one inherited the MovementComponent 466 00:39:26.709 --> 00:39:30.679 If you look, this one inherited the ActorComponent 467 00:39:30.679 --> 00:39:33.659 Since they have't inherited SceneComponent 468 00:39:33.659 --> 00:39:35.709 This one doesn't have Transform 469 00:39:35.709 --> 00:39:39.080 That's why we cannot Attach them 470 00:39:41.009 --> 00:39:44.559 This should be good to know also 471 00:39:46.009 --> 00:39:48.359 Let's go back 472 00:39:48.359 --> 00:39:50.709 Let's add header for this one too 473 00:39:50.709 --> 00:39:54.159 Add it like so 474 00:39:55.600 --> 00:39:57.800 And next, this is 475 00:39:57.800 --> 00:40:01.959 Since MovementComponent cannot 476 00:40:01.959 --> 00:40:04.308 Use Transform by itself 477 00:40:04.308 --> 00:40:08.108 We have to have it depend on other components 478 00:40:08.108 --> 00:40:10.908 If you don't designate UpdateComponent 479 00:40:10.908 --> 00:40:13.639 It will utilize RootComponent 480 00:40:13.639 --> 00:40:16.458 If one decides to leave RootComponent alone 481 00:40:16.458 --> 00:40:20.600 And decides to use and fire collision object 482 00:40:20.600 --> 00:40:24.758 with other components, We can use MeshComponent 483 00:40:26.058 --> 00:40:30.208 Collision doesn't do anything and Mesh will shoot out byitself 484 00:40:30.208 --> 00:40:34.560 So let's just set it to the root 485 00:40:34.560 --> 00:40:37.908 It seems like that it's better to have the CollisionComponent itself shooting out 486 00:40:37.908 --> 00:40:40.959 Let's match it like this 487 00:40:40.959 --> 00:40:45.208 Since this is a projectile, there are several attributes 488 00:40:45.208 --> 00:40:50.439 If we look at it here, we have something called InitialSpeed 489 00:40:50.439 --> 00:40:55.479 Let's have the initial speed as 5000 490 00:40:55.479 --> 00:41:00.558 And in the MovementComponent 491 00:41:00.558 --> 00:41:03.558 There is something called MaxSpeed, speaks for itself 492 00:41:03.558 --> 00:41:06.579 This one is initial speed and that one is the maximum speed 493 00:41:06.579 --> 00:41:09.800 If one decides to have the speed gradually going up, you would set them as different values 494 00:41:09.800 --> 00:41:12.158 But I want to set them at a constant speed 495 00:41:12.158 --> 00:41:15.059 Therefore, MaxSpeed will have the same value of 5000 496 00:41:17.608 --> 00:41:21.208 Also, I would like it to bounce 497 00:41:21.208 --> 00:41:24.120 I would like it to bounce 498 00:41:24.120 --> 00:41:29.120 So, we use bShouldBounce 499 00:41:29.120 --> 00:41:33.170 Set it as true for allowing the projectile to bounce on the ground 500 00:41:34.158 --> 00:41:39.689 Also, we can decide how bouncy it will be using Bounciness 501 00:41:42.558 --> 00:41:46.708 The value should be from 0 to 1 502 00:41:46.708 --> 00:41:49.019 Let's try 0.3 503 00:41:50.508 --> 00:41:55.408 And I would like it to be block instead of overlap 504 00:41:55.408 --> 00:41:59.258 I want the effect of the object to handle every other objects as blocks 505 00:41:59.258 --> 00:42:00.719 To actually hit every objects 506 00:42:00.719 --> 00:42:02.869 So that the projectile will bounce around like I want it to 507 00:42:02.869 --> 00:42:07.508 Put CollisionComponent in SpheereComponent 508 00:42:09.058 --> 00:42:14.890 We want SetCollisionProfile and write TEXT 509 00:42:16.399 --> 00:42:18.908 This one here, I want it to become block with every other objects 510 00:42:18.908 --> 00:42:22.608 So, designate BlockAll like this 511 00:42:22.608 --> 00:42:26.608 This is already a configured name 512 00:42:26.608 --> 00:42:33.159 if you go to Edit Project Settings and look under Collision 513 00:42:33.159 --> 00:42:35.907 In the Preset section, we can find BlockAll 514 00:42:35.907 --> 00:42:37.840 I used this exact name 515 00:42:38.840 --> 00:42:44.379 There's something that's already been designated 516 00:42:47.439 --> 00:42:50.007 And next, for Mesh, it should not collide 517 00:42:50.007 --> 00:42:51.557 Let's turn off Mesh as collision object 518 00:42:51.557 --> 00:43:02.107 Just like before, put SetCollisionProfile to Mesh and then TEXT 519 00:43:02.107 --> 00:43:06.657 Set NoCollision 520 00:43:06.657 --> 00:43:10.007 This name is also over there 521 00:43:10.007 --> 00:43:13.360 If you look here, you can find NoCollision 522 00:43:13.360 --> 00:43:17.609 I just used this name 523 00:43:21.207 --> 00:43:24.959 Now, compile one more time 524 00:43:29.939 --> 00:43:34.107 Then we should give it a shape 525 00:43:34.107 --> 00:43:37.530 We can handle this as well 526 00:43:37.530 --> 00:43:40.707 But this would be too big for a bullet, the diameter being 1m long 527 00:43:41.607 --> 00:43:44.560 We should reduce the size 528 00:43:44.560 --> 00:43:49.357 It's set to 32 here, but I'll reduce it to around 13 529 00:43:49.357 --> 00:43:52.009 Let's insert an appearance 530 00:43:56.280 --> 00:44:01.107 This one is 1m long 531 00:44:01.107 --> 00:44:04.957 The collide object is really small but this one is big 532 00:44:04.957 --> 00:44:08.439 Let's try reducing the size like this 533 00:44:08.439 --> 00:44:09.507 Reduce the size about like this 534 00:44:09.507 --> 00:44:13.507 0.25 works just fine 535 00:44:13.507 --> 00:44:16.760 About 0.25 must be good enough 536 00:44:16.760 --> 00:44:20.607 Compile it and switch the Material as well 537 00:44:20.607 --> 00:44:29.489 Search for Basic Shape Material 538 00:44:33.080 --> 00:44:36.607 After the bullet is fired 539 00:44:36.607 --> 00:44:40.439 And as long as you don't turn off the app, it will exist forever 540 00:44:40.439 --> 00:44:43.610 Let's shoot some first 541 00:44:45.000 --> 00:44:49.156 If you look, it flies away 542 00:44:49.156 --> 00:44:52.560 What we want is that we want them to disappear after some time 543 00:44:52.560 --> 00:44:55.306 So, let's give it some amount of lifespan 544 00:44:55.306 --> 00:44:57.806 If you look here, you can find Life Span 545 00:44:57.806 --> 00:45:01.360 Set it as Default 546 00:45:01.360 --> 00:45:05.456 Give the value for the Life Span 547 00:45:05.456 --> 00:45:09.959 Should we designate it as C while we're at it? 548 00:45:09.959 --> 00:45:13.956 Here, you can find SetLifeSpan 549 00:45:13.956 --> 00:45:19.120 Three seconds? You can set the time here 550 00:45:19.120 --> 00:45:22.256 In float, lifespan is entered like this, in seconds 551 00:45:22.256 --> 00:45:25.760 So if you set the value as 3, it will disappear after 3 seconds 552 00:45:25.760 --> 00:45:29.656 Let's say 3 seconds 553 00:45:30.660 --> 00:45:32.999 So, compile it like this 554 00:45:37.956 --> 00:45:41.906 Now, if I do left mouse click 555 00:45:41.906 --> 00:45:45.406 We can actually have the bullet generated for firing 556 00:45:45.406 --> 00:45:48.856 So the bullets do disappear after 3 seconds but it's hard to notice 557 00:45:48.856 --> 00:45:53.090 Then let's go to the player and implement that 558 00:45:54.040 --> 00:46:01.106 Start with UPROPERTY and EditAnywhere 559 00:46:01.106 --> 00:46:08.220 TSubclassOf then class with AbulletActor 560 00:46:12.206 --> 00:46:17.299 And then BulletFactory 561 00:46:20.320 --> 00:46:22.706 So when fired, we can generate bullets 562 00:46:22.706 --> 00:46:24.056 And place them 563 00:46:24.056 --> 00:46:27.009 And while we are at it, let's do this too 564 00:46:30.519 --> 00:46:34.156 When ShiperFun is fired, VFX will be activated as well 565 00:46:34.156 --> 00:46:37.320 So, let's make that happen here 566 00:46:37.320 --> 00:46:41.206 So let's use the same method with UPROPERTY 567 00:46:41.206 --> 00:46:50.429 Enter Class UParticlSystem like this 568 00:46:50.429 --> 00:46:54.089 And add ExplosionVFXFactory 569 00:46:57.159 --> 00:46:58.956 Let's implement this first 570 00:46:58.956 --> 00:47:02.406 If you go this way, you just need to handle 571 00:47:02.406 --> 00:47:06.940 The Fire part in the player's source file 572 00:47:08.140 --> 00:47:12.159 It needs to be fired differently depending on the type of gun 573 00:47:12.159 --> 00:47:18.605 So if bChooseGun is true, it means we create bullets 574 00:47:18.605 --> 00:47:22.455 And if bSniperGun is true, it means it's a sniper 575 00:47:23.455 --> 00:47:26.805 We'll use something called Line Trace to handle the impact 576 00:47:26.805 --> 00:47:30.705 When it is else, we'll fire default gun 577 00:47:30.705 --> 00:47:34.859 This is the default gun and this one is sniper rifle 578 00:47:36.655 --> 00:47:42.355 Let's handle default first, we need actual bullet generation location 579 00:47:42.355 --> 00:47:44.479 Yes, we need to set the location 580 00:47:44.479 --> 00:47:46.155 We can do this one 581 00:47:46.155 --> 00:47:50.029 This is what actual model is for our default gun 582 00:47:51.055 --> 00:47:55.005 We can use the coordinates over here 583 00:47:55.005 --> 00:47:57.199 The Muzzle here looks like this 584 00:47:57.955 --> 00:48:00.605 And we want to generate bullets over here 585 00:48:00.605 --> 00:48:09.605 So, I'll make a copy of the Muzzle 586 00:48:09.605 --> 00:48:12.755 And name it Paste Socket here 587 00:48:12.755 --> 00:48:15.205 Then an additional Muzzle is made 588 00:48:15.205 --> 00:48:18.609 Then this is FirePosition 589 00:48:21.399 --> 00:48:25.105 And let's pull the location a bit to the front 590 00:48:25.105 --> 00:48:28.719 We want the bullets to be generated here 591 00:48:28.719 --> 00:48:30.805 And this one must be saved 592 00:48:30.805 --> 00:48:35.919 In order to use this, make sure you remember the name as well 593 00:48:35.919 --> 00:48:41.055 If you press F2, you can copy it 594 00:48:41.055 --> 00:48:42.605 Make sure you save it 595 00:48:42.605 --> 00:48:45.039 To be for sure, save the entire file 596 00:48:45.605 --> 00:48:47.955 After that, come back here 597 00:48:47.955 --> 00:48:51.055 Now let's create it here 598 00:48:51.055 --> 00:48:56.199 It is located in GunMesh 599 00:48:56.199 --> 00:49:07.155 Write GunMesh, and GetSocketTransform 600 00:49:07.155 --> 00:49:13.670 And then put TEXT with the name FirePosition 601 00:49:13.670 --> 00:49:17.605 Bring the SocketTransform with that name 602 00:49:17.605 --> 00:49:25.755 Make this FTransform 603 00:49:25.755 --> 00:49:28.305 And write t for it 604 00:49:29.155 --> 00:49:30.755 Now let's create it 605 00:49:30.755 --> 00:49:37.505 GetWorld and then SpawnActor 606 00:49:37.505 --> 00:49:43.399 ABulletActor so we can generate bullets 607 00:49:44.204 --> 00:49:47.504 So, BulletFactory comes in 608 00:49:47.504 --> 00:49:49.870 And then add t like this 609 00:49:51.204 --> 00:49:54.504 It means that the bullets will be made at that Transform location 610 00:49:54.504 --> 00:49:57.054 There's not much more to do anything 611 00:49:57.054 --> 00:49:59.840 This would be sufficient enough for the bullets to fire 612 00:49:59.840 --> 00:50:03.080 Let's try it out, so compile it 613 00:50:09.554 --> 00:50:13.104 We get an error, probably made because I didn't add the header 614 00:50:13.104 --> 00:50:16.354 Let's add the header like this, ABulletActor 615 00:50:24.320 --> 00:50:30.804 Let's run it again, the gun's not firing 616 00:50:30.804 --> 00:50:35.604 Then now let's check from the keys 617 00:50:35.604 --> 00:50:42.429 The key, left mouse button is set right but the gun doesn't fire 618 00:50:46.079 --> 00:50:49.030 IA is registered with no problem 619 00:50:54.004 --> 00:50:56.404 In cases like this, it's better to look at some logs 620 00:50:56.404 --> 00:50:58.204 Let's find out if this comes in 621 00:50:58.204 --> 00:51:10.354 UE Log LogTemp and then Warning 622 00:51:12.654 --> 00:51:15.099 Let's look at some TEXT 623 00:51:22.870 --> 00:51:27.104 I didn't put Factory here 624 00:51:27.104 --> 00:51:30.280 I will fill this up, this could be the reason 625 00:51:30.280 --> 00:51:34.839 Fill it up here as well and then run it again 626 00:51:35.354 --> 00:51:38.304 It works fine now, we found the problem 627 00:51:38.304 --> 00:51:43.560 Finally, let's fire SniperGun 628 00:51:45.454 --> 00:51:51.159 For sniper, rifle we will do it this way 629 00:51:51.159 --> 00:51:54.454 Till now, for collision 630 00:51:54.454 --> 00:51:57.404 We imagined an object colliding with another 631 00:51:57.404 --> 00:51:59.054 That was the kind of collision we were working with 632 00:51:59.054 --> 00:52:01.154 And then there was event and so on 633 00:52:01.154 --> 00:52:05.654 This time, let's say we draw a line 634 00:52:05.654 --> 00:52:08.553 From a point to a point 635 00:52:08.553 --> 00:52:10.853 If there is collision object in the line 636 00:52:10.853 --> 00:52:12.953 We will make it detect objects 637 00:52:12.953 --> 00:52:17.103 Compared to human, it can be the point of view 638 00:52:17.103 --> 00:52:22.753 To create a gaze like this and detect when an object is detected here 639 00:52:22.753 --> 00:52:28.103 We look and it touches here 640 00:52:29.560 --> 00:52:33.003 Let's create a function that can detect 641 00:52:33.003 --> 00:52:40.653 In Unreal Engine, it is called Line Trace 642 00:52:40.653 --> 00:52:43.253 Line Trace serves two different roles 643 00:52:43.253 --> 00:52:45.603 It can utilize object channel 644 00:52:45.603 --> 00:52:47.600 And trace channel 645 00:52:47.600 --> 00:52:50.903 This time, let's use trace channel 646 00:52:50.903 --> 00:52:53.389 To handle this 647 00:52:59.953 --> 00:53:04.489 Here, write GetWorld 648 00:53:06.800 --> 00:53:09.303 Write Line Trace 649 00:53:09.303 --> 00:53:12.203 There are many commands like Trace By Channel 650 00:53:12.203 --> 00:53:16.003 Let's use Single By Channel this time 651 00:53:16.003 --> 00:53:22.053 If you look here, the variable is FHitResult and from start to end 652 00:53:22.053 --> 00:53:25.360 To draw a line, you need two coordinates 653 00:53:25.360 --> 00:53:29.453 This would be the locations for that 654 00:53:29.453 --> 00:53:31.803 And then, what it will look at 655 00:53:31.803 --> 00:53:34.703 This is the filtering 656 00:53:34.703 --> 00:53:36.003 Parameter comes in here 657 00:53:36.003 --> 00:53:39.080 Let's try constructing all of this 658 00:53:39.080 --> 00:53:47.689 Let's start with FHitResult hitInfo 659 00:53:47.689 --> 00:53:53.280 Let's write FVector with start 660 00:53:53.280 --> 00:54:08.803 This is camera, CamComp and GetComponentLocation 661 00:54:08.803 --> 00:54:13.653 And then there is FVector end 662 00:54:13.653 --> 00:54:19.080 End value will be Start plus CamComp's aligned direction 663 00:54:19.080 --> 00:54:25.103 Here, GetForwardVector 664 00:54:25.103 --> 00:54:31.902 Multiply about 100m? If you want more, add more 665 00:54:31.902 --> 00:54:34.752 It can as far as 1km for example 666 00:54:34.752 --> 00:54:37.452 A Parameter is required here as well 667 00:54:37.452 --> 00:54:41.080 There is something called FCollisionQueryParams 668 00:54:41.080 --> 00:54:45.502 Write Params 669 00:54:45.502 --> 00:54:47.952 Many different commands can go, but the most important would be 670 00:54:47.952 --> 00:54:52.002 Excluding myself there by using AddIgnoreVector 671 00:54:52.002 --> 00:54:56.652 Wrtie this to exclude myself 672 00:54:57.652 --> 00:55:02.470 And then put everything in here, hitInfo and then start 673 00:55:04.239 --> 00:55:10.600 And then end, the one I will be facting, ECC Visibility 674 00:55:10.600 --> 00:55:16.230 And then add params 675 00:55:17.280 --> 00:55:20.479 So, bool and bHit 676 00:55:22.360 --> 00:55:25.402 Let's check the collision 677 00:55:25.402 --> 00:55:30.239 The return value would be the bool and when collided, it will be true 678 00:55:30.239 --> 00:55:32.652 The actual collision info will be in hitInfo 679 00:55:32.652 --> 00:55:38.602 Therefore, if bHit is true 680 00:55:38.602 --> 00:55:42.040 Then at the location, VFX will be made 681 00:55:42.040 --> 00:55:46.359 So, UGameplayStatics 682 00:55:49.402 --> 00:55:54.252 If you look here, you can use SpawnEmitterAtLocation 683 00:55:54.252 --> 00:55:58.129 Add GetWorld here 684 00:56:00.479 --> 00:56:04.002 And then ExplosionVFXFactory follows 685 00:56:04.002 --> 00:56:06.902 We need to put the location which is in the hitInfo 686 00:56:06.902 --> 00:56:13.052 In the hitInfo, there is a Point which is the concept of Impact 687 00:56:13.052 --> 00:56:16.320 This is the actual collision location 688 00:56:16.320 --> 00:56:19.880 So we've made it and add the header 689 00:56:24.600 --> 00:56:27.200 And then compile it 690 00:56:36.939 --> 00:56:43.920 If you run it, at the hit point you can see the VFX activating 691 00:56:45.520 --> 00:56:49.952 Let's summarize everything we've learned in this session 692 00:56:49.952 --> 00:56:51.102 Placing grenade launcher and sniper rifle 693 00:56:51.102 --> 00:56:52.302 Setting the materials for the grenade launcher and sniper rifle Created as components of the character 694 00:56:52.302 --> 00:56:53.452 Implementing functionality for the grenade launcher and sniper rifle 695 00:56:53.452 --> 00:56:55.202 Implementing functionality for the grenade launcher, creating bullet actors Handles projectile object using ProjectileMovementComponent 696 00:56:55.202 --> 00:56:56.951 Implementing functionality for the sniper rifle Line trace, used for collision detection 697 00:56:56.951 --> 00:56:58.951 Implementing gun swapping and crosshair 698 00:56:58.951 --> 00:57:01.901 At first, starting with the default gun since it's false Declared an InputAction for key input and set it up in the blueprint 699 00:57:01.901 --> 00:57:04.851 SetVisibility function Handling the Crosshair by enabling or disabling the widget component