1 00:00:28.025 --> 00:00:29.778 Hello, this is Yeong-hoon Lee 2 00:00:30.253 --> 00:00:33.594 Today, we are going to try making bullets and enemies 3 00:00:33.990 --> 00:00:38.366 Using the Spawner system and input, we are going to fire the bullet 4 00:00:38.593 --> 00:00:41.513 and learn about how to create the enemy 5 00:00:41.860 --> 00:00:46.065 First, we'll learn about ways to make and move the bullet 6 00:00:46.475 --> 00:00:50.356 Creating and Firing the Bullet 7 00:00:51.936 --> 00:00:58.366 We are going to create the bullet actor and the enemy actor and control them 8 00:00:59.010 --> 00:01:01.197 Let's try making the bullet first 9 00:01:02.465 --> 00:01:04.376 Go to the project 10 00:01:05.158 --> 00:01:06.952 Open the blueprint foler 11 00:01:07.170 --> 00:01:09.172 Right click here 12 00:01:09.776 --> 00:01:12.095 We are going to create a blueprint class 13 00:01:13.986 --> 00:01:15.502 We are going to create actor 14 00:01:15.502 --> 00:01:18.139 We're not controlling it because it's a bullet 15 00:01:18.139 --> 00:01:19.963 It's supposed to travel forward by itself 16 00:01:20.230 --> 00:01:25.665 We are going to create a blueprint class that is based off of actor 17 00:01:26.387 --> 00:01:31.369 We'll name it "BP_Bullet" 18 00:01:33.379 --> 00:01:37.817 Create the Bullet and double click on it 19 00:01:40.153 --> 00:01:44.676 We're going to rotate it a little by using the Alt key 20 00:01:45.746 --> 00:01:47.321 I'll rotate it like this 21 00:01:47.609 --> 00:01:48.987 so that the X faces upward 22 00:01:50.245 --> 00:01:54.594 How I'm going to make the object, is like this 23 00:01:56.346 --> 00:01:58.580 If there's an object, so if there's a player here 24 00:01:58.580 --> 00:02:03.065 The player is moving up down, right and left 25 00:02:03.580 --> 00:02:06.702 I'm going to make an arrow here 26 00:02:07.355 --> 00:02:09.904 And at the location of this arrow, I'm going to make the bullet appear 27 00:02:10.122 --> 00:02:13.308 But the bullet won't be as fat as the player 28 00:02:13.308 --> 00:02:16.394 I want to make a thin bullet that looks like this 29 00:02:18.038 --> 00:02:19.696 I want to make a bullet like this 30 00:02:20.003 --> 00:02:23.208 The bullet will travel forward in this direction 31 00:02:25.336 --> 00:02:26.642 Since I will process it like this 32 00:02:27.018 --> 00:02:30.535 When I look at the bullet, then it should look like this 33 00:02:31.020 --> 00:02:32.693 This part is the front 34 00:02:34.703 --> 00:02:41.989 I'll rotate it so that this would be the forward direction in the bullet's point of view 35 00:02:43.385 --> 00:02:46.903 The bullet would travel towards the front side of itself 36 00:02:47.962 --> 00:02:52.057 So we're going to make the bullet 37 00:02:52.789 --> 00:02:58.663 In BP_Bullet, click the Add button of the components tab 38 00:02:59.059 --> 00:03:00.564 We'll make a cube 39 00:03:02.386 --> 00:03:03.168 Then it looks like this 40 00:03:06.357 --> 00:03:09.045 When you press the Alt key, you can take a look like this 41 00:03:09.045 --> 00:03:10.423 It would originally look like this 42 00:03:11.077 --> 00:03:12.756 We're going to rotate it like this 43 00:03:13.767 --> 00:03:15.731 So that the red arrow points up 44 00:03:16.048 --> 00:03:20.664 And let the green arrow point to the right 45 00:03:20.664 --> 00:03:21.886 We'll rotate it this way 46 00:03:22.698 --> 00:03:25.925 Then we're going to compress this 47 00:03:26.479 --> 00:03:29.945 Let's decrease the scale and make it longer 48 00:03:30.806 --> 00:03:34.686 Press the R button, and you'll be able to adjust the scale 49 00:03:35.765 --> 00:03:37.130 And the green here 50 00:03:38.120 --> 00:03:42.606 Hold the green axis with the left click of the mouse 51 00:03:44.220 --> 00:03:45.677 Decrease it like this 52 00:03:46.330 --> 00:03:49.371 When you look here, the value for green 53 00:03:49.371 --> 00:03:51.965 The Y value will be something like 0.25 54 00:03:52.816 --> 00:03:56.159 Let's shorten the height as well, to about this much 55 00:03:57.535 --> 00:04:02.367 Then the settings should be at 0.75, 0.25, 1 56 00:04:06.604 --> 00:04:08.009 Compile this 57 00:04:10.876 --> 00:04:13.107 We're going to move the bullet forward 58 00:04:13.107 --> 00:04:15.248 It will travel this way, right? 59 00:04:15.901 --> 00:04:20.985 We'll do this job at the Event Graph tab 60 00:04:22.193 --> 00:04:25.654 At Event Graph, if you hold onto right-click and move, it will move like this 61 00:04:26.456 --> 00:04:29.488 Come over here, and since it's going to move 62 00:04:29.488 --> 00:04:32.910 It's not going to move just once after appearing 63 00:04:32.910 --> 00:04:34.572 It has to continue moving 64 00:04:34.830 --> 00:04:36.542 So we're not going to use BeginPlay 65 00:04:37.344 --> 00:04:41.244 We're going to use Event Tick 66 00:04:43.937 --> 00:04:44.780 We're going to be here 67 00:04:45.404 --> 00:04:47.330 And here as well, it's going to move forward 68 00:04:48.092 --> 00:04:51.052 In order to create the forward direction 69 00:04:52.517 --> 00:04:59.475 For forward direction, there's something called Get Actor Forward Vector 70 00:05:00.178 --> 00:05:03.715 This is the vector for the forward direction 71 00:05:03.973 --> 00:05:05.996 Our forward direction 72 00:05:06.135 --> 00:05:12.918 Or since it's forward direction, we can also use Make Vector 73 00:05:12.918 --> 00:05:15.495 There's a difference between these two and we'll also look into this 74 00:05:16.297 --> 00:05:20.353 Then forward means that X will be 1 75 00:05:22.220 --> 00:05:23.688 Enter the value like this 76 00:05:24.015 --> 00:05:27.128 And since the object will move forward 77 00:05:27.128 --> 00:05:28.988 We'll also use the motion formula 78 00:05:28.988 --> 00:05:34.068 Last time, we used the equation P=P0 vt 79 00:05:34.365 --> 00:05:35.888 to move 80 00:05:36.234 --> 00:05:39.227 We'll try moving it using the same method 81 00:05:40.227 --> 00:05:41.594 Let's type it here (in the comment box) 82 00:05:41.594 --> 00:05:46.677 We'll put P=P0 vt 83 00:05:53.665 --> 00:05:55.705 Let me talk about this a little more 84 00:05:57.348 --> 00:06:03.274 Last time, we learned about moving with P=P0 vt 85 00:06:04.016 --> 00:06:06.104 as well as velocity 86 00:06:06.530 --> 00:06:11.235 We'll need more explanation on delta time, or delta second 87 00:06:11.938 --> 00:06:16.923 So we'll continue on from here 88 00:06:17.953 --> 00:06:27.453 When we move, we use the motion equation P=P0 vt 89 00:06:27.958 --> 00:06:32.608 We call this velocity 90 00:06:33.430 --> 00:06:38.675 Velocity is a quantity that has direction and magnitude 91 00:06:39.398 --> 00:06:41.298 This of course, is in vector 92 00:06:42.318 --> 00:06:43.130 These are all vectors 93 00:06:45.537 --> 00:06:47.519 Then what's t? 94 00:06:48.083 --> 00:06:52.191 For time, let's say in animations or 95 00:06:52.191 --> 00:06:55.364 dramas, what happens when we stop time? 96 00:06:55.849 --> 00:06:57.196 All movements stop 97 00:06:57.889 --> 00:06:58.998 Look at this equation 98 00:06:59.404 --> 00:07:03.473 There's direction and magnitude, but if the time is 0 99 00:07:03.849 --> 00:07:05.941 The initial location and the current location becomes equal 100 00:07:05.941 --> 00:07:07.071 Meaning, it doesn't move 101 00:07:07.665 --> 00:07:09.913 So the concept of time is very important 102 00:07:10.537 --> 00:07:14.225 Then we can think of time like this 103 00:07:14.561 --> 00:07:17.420 Let's say that there are two computers 104 00:07:17.420 --> 00:07:21.733 One computer can calculate twice in 1 second 105 00:07:22.396 --> 00:07:23.457 Twice in 1 second 106 00:07:24.021 --> 00:07:26.610 And another computer is twice as more advanced than this 107 00:07:26.610 --> 00:07:30.646 So let's say that it can calculate four times in 1 second 108 00:07:32.507 --> 00:07:36.796 Then let's take these computer A and computer B 109 00:07:36.796 --> 00:07:38.413 And let's say that we'll play a game 110 00:07:39.116 --> 00:07:41.698 We'll play a game of running forward 111 00:07:42.104 --> 00:07:45.909 Then this, calculating twice in 1 second 112 00:07:45.909 --> 00:07:49.549 Every time I draw, if it moves 1 meter 113 00:07:49.876 --> 00:07:54.194 And this also moves 1 meter, then it's pay-to-win, right? 114 00:07:54.194 --> 00:07:58.437 Those who pay, those with better computers will win 115 00:07:58.595 --> 00:08:00.461 This can go 2 meters and this can go 4 meters 116 00:08:01.114 --> 00:08:04.955 Then we need to think about how to make this fair 117 00:08:06.312 --> 00:08:07.924 Then we can do this 118 00:08:09.142 --> 00:08:12.660 This is twice in 1 second, right? 119 00:08:12.660 --> 00:08:14.683 Then let's divide this by 2 120 00:08:16.108 --> 00:08:17.647 This is four times in 1 second 121 00:08:17.647 --> 00:08:19.010 Then divide this by 4 122 00:08:23.530 --> 00:08:24.678 Let's add up now 123 00:08:24.678 --> 00:08:29.886 1/2 is 0.5, so 0.5 and 0.5, right? 124 00:08:30.104 --> 00:08:31.481 This becomes 1 125 00:08:32.214 --> 00:08:34.251 This too, 1/4 is 0.25 126 00:08:38.140 --> 00:08:40.738 0.25 127 00:08:41.193 --> 00:08:47.038 Add up all the 0.25, and you'll get 1 128 00:08:47.870 --> 00:08:51.401 This is the concept 129 00:08:51.401 --> 00:08:57.021 So these values, like 0.5 or 0.25 130 00:08:57.199 --> 00:09:00.533 becomes delta time, or delta second 131 00:09:01.899 --> 00:09:04.511 What effect does this have? 132 00:09:04.848 --> 00:09:09.075 It becomes fair. And let me express this in a more technical way 133 00:09:09.867 --> 00:09:13.577 Our computer doesn't draw out the screen at once 134 00:09:13.577 --> 00:09:18.239 It may be 30 times a second or 60 times 135 00:09:19.140 --> 00:09:24.214 Monitors these days draw much more times, such as 144 times 136 00:09:25.028 --> 00:09:26.756 There are some that draw more 137 00:09:26.756 --> 00:09:30.367 So it's the concept of "how many times to draw in 1 second" 138 00:09:30.367 --> 00:09:34.238 These number of times are called frames 139 00:09:37.183 --> 00:09:40.069 So we call it FPS 140 00:09:42.148 --> 00:09:47.247 Frame Per Second 141 00:09:49.009 --> 00:09:51.736 We call it Frame Per Second 142 00:09:51.736 --> 00:09:55.433 It expresses the number of frames for each second 143 00:09:56.037 --> 00:09:57.316 Then what this is 144 00:09:57.316 --> 00:10:02.441 This is two times for 1 second, so 2 frames 145 00:10:02.441 --> 00:10:04.498 So the FPS for this is 0.5 146 00:10:06.419 --> 00:10:08.335 No, 2 FPS 147 00:10:09.306 --> 00:10:10.950 The bottom one is 4 FPS 148 00:10:11.336 --> 00:10:12.763 This is slow 149 00:10:12.763 --> 00:10:16.420 The computers these days draw out 60 FPS 150 00:10:16.836 --> 00:10:20.238 In the actual unreal, to see what we're drawing 151 00:10:21.179 --> 00:10:23.901 If you look here, you can check the FPS 152 00:10:23.901 --> 00:10:29.039 Press Show FPS, and it says 19 FPS right now 153 00:10:29.227 --> 00:10:34.582 When you play it, it is about 60 FPS 154 00:10:34.770 --> 00:10:38.082 Millisecond is 1/1000 second, so it's about 17/1000 seconds 155 00:10:39.379 --> 00:10:44.858 That was the concept of FPS 156 00:10:45.264 --> 00:10:49.598 So this concept of delta time, or delta second 157 00:10:49.984 --> 00:10:52.212 Is very closely related to FPS 158 00:10:52.757 --> 00:10:55.038 It's the amount of time it takes to draw one frame 159 00:10:55.038 --> 00:10:59.179 So the time between current frame and previous frame 160 00:10:59.179 --> 00:11:03.301 This is delta time, or delta second 161 00:11:03.301 --> 00:11:04.891 So that's the concept 162 00:11:05.169 --> 00:11:07.235 So where we multiply this, is 163 00:11:07.581 --> 00:11:10.223 We usually multiply this by the transform value 164 00:11:10.480 --> 00:11:11.916 There are 3 types of transform 165 00:11:12.272 --> 00:11:15.500 Location, rotation, and scale 166 00:11:15.500 --> 00:11:18.931 For example, if we're making a running game 167 00:11:18.931 --> 00:11:21.915 Then multiply the location by delta second, and it will become fair 168 00:11:22.420 --> 00:11:23.725 But there's a difference, though 169 00:11:24.468 --> 00:11:27.921 When there are more frames, the frames become smoother 170 00:11:27.921 --> 00:11:29.673 For the same 1 second, 171 00:11:30.030 --> 00:11:35.125 If it's 60, it's 60 times per second, so it's smooth 172 00:11:35.125 --> 00:11:37.720 If there are 20 frames, 173 00:11:37.868 --> 00:11:40.775 It's 20 times per second, so it will feel choppy 174 00:11:41.468 --> 00:11:43.434 But the result is the same 175 00:11:43.810 --> 00:11:46.339 Making it fair like this 176 00:11:46.864 --> 00:11:48.469 Is what delta second does 177 00:11:51.281 --> 00:11:53.231 This is how we process it 178 00:11:54.063 --> 00:11:57.731 So taking this, we're going to actually move it 179 00:11:57.731 --> 00:12:01.110 Let's set X to 1, and now we need to make speed 180 00:12:01.110 --> 00:12:05.103 Type Speed here 181 00:12:05.103 --> 00:12:09.439 This is a bullet, so let's make it move fast 182 00:12:10.390 --> 00:12:14.464 About twice as fast as the player. The player is 500, or 5m, so 183 00:12:14.979 --> 00:12:19.198 10m. Let's move it with the value of 1000 184 00:12:21.857 --> 00:12:24.085 And now we just need to multiply the speed here 185 00:12:24.085 --> 00:12:28.525 This is the direction, so multiply 186 00:12:30.020 --> 00:12:31.318 Multiply the speed like this 187 00:12:31.674 --> 00:12:34.241 Then we also need to multiply delta second 188 00:12:34.241 --> 00:12:36.329 Add another pin and multiply right away 189 00:12:36.329 --> 00:12:39.437 Then this part becomes vt 190 00:12:40.526 --> 00:12:41.957 Then go to Get Actor Location 191 00:12:45.580 --> 00:12:46.713 This is P0 192 00:12:47.911 --> 00:12:51.381 P0 plus... We need to set to add 193 00:12:52.490 --> 00:12:57.669 Do P0 vt, and it becomes New Location 194 00:12:59.908 --> 00:13:03.879 Over here, put Set Actor Location 195 00:13:07.127 --> 00:13:10.653 Set it like this, and now it will move forward 196 00:13:11.148 --> 00:13:12.528 Connect them like this 197 00:13:13.469 --> 00:13:19.446 When you follow after me, watch the flow of lines carefully 198 00:13:20.050 --> 00:13:23.491 If you miss something, it will not move properly 199 00:13:23.798 --> 00:13:25.192 Don't forget these connections 200 00:13:25.786 --> 00:13:27.438 Make it like that 201 00:13:30.659 --> 00:13:34.399 Let's see if it actually works. Take out the bullet 202 00:13:34.399 --> 00:13:37.079 It looks like this, and once we play it 203 00:13:38.020 --> 00:13:39.124 It looks like it's staying still 204 00:13:39.124 --> 00:13:41.807 That's because it's moving forward 205 00:13:42.312 --> 00:13:44.922 If you look at the Bullet, 206 00:13:45.219 --> 00:13:47.049 X keeps increasing 207 00:13:47.049 --> 00:13:49.738 But since we have direct projection 208 00:13:49.986 --> 00:13:52.007 Since there's no perception 209 00:13:52.007 --> 00:13:54.804 It looks like it's not moving because the size is the same 210 00:13:56.754 --> 00:13:58.501 So we're going to rotate this 211 00:13:58.501 --> 00:14:02.913 Go to the y axis 212 00:14:03.072 --> 00:14:05.659 Rotate the y axis 90 degrees 213 00:14:05.659 --> 00:14:06.702 Then it will become like this 214 00:14:07.226 --> 00:14:10.073 It looks like there's no change in axis 215 00:14:10.073 --> 00:14:12.123 But that's because it's in global 216 00:14:12.123 --> 00:14:13.417 Click this 217 00:14:14.219 --> 00:14:16.574 And you'll see the red arrow now pointing up 218 00:14:18.159 --> 00:14:22.089 Let's set the location to a little above the character 219 00:14:22.089 --> 00:14:22.841 Let's move up 220 00:14:24.167 --> 00:14:26.790 Huh why isn't it moving 221 00:14:27.186 --> 00:14:30.366 Oh~ Right, of course it doesn't move 222 00:14:30.366 --> 00:14:33.049 Because look 223 00:14:33.416 --> 00:14:37.174 Play it, and the X is moving, right? 224 00:14:38.055 --> 00:14:40.153 We rotated it, right? 225 00:14:40.520 --> 00:14:41.719 But X is moving 226 00:14:41.719 --> 00:14:44.764 That's because we used Make Vector 227 00:14:44.764 --> 00:14:47.889 And said, move in the direction of X 228 00:14:49.087 --> 00:14:51.184 This is like the concept of NSEW 229 00:14:51.452 --> 00:14:54.052 We said, move inward towards the screen, right? 230 00:14:54.497 --> 00:14:58.699 So in the world coordinate, we said move towards the front of the world 231 00:14:58.699 --> 00:15:00.218 That's how we processed it 232 00:15:00.446 --> 00:15:02.768 So regardless of our rotation 233 00:15:02.768 --> 00:15:04.847 It continues to move forward 234 00:15:05.778 --> 00:15:08.900 So instead of this, let's change this 235 00:15:08.900 --> 00:15:13.597 Cut this off, and change it to Get Actor Forward Vector 236 00:15:14.340 --> 00:15:14.938 Like this 237 00:15:18.453 --> 00:15:22.773 Then play it, and you'll see how it moves upward 238 00:15:22.773 --> 00:15:23.812 It moves up 239 00:15:25.287 --> 00:15:27.566 You can see it traveling up 240 00:15:28.576 --> 00:15:30.066 Process it like this 241 00:15:30.938 --> 00:15:33.650 The difference between these two is very important 242 00:15:33.650 --> 00:15:36.252 Make Vector sets the absolute coordinates 243 00:15:36.668 --> 00:15:42.325 So it's the difference between forward direction of the world coordinate 244 00:15:42.325 --> 00:15:45.783 Versus the forward direction in my point of view 245 00:15:45.783 --> 00:15:49.539 This allows various methods of processing 246 00:15:50.806 --> 00:15:53.013 After this, then let's say that 247 00:15:54.340 --> 00:15:55.975 We are trying to rotate this 248 00:15:56.905 --> 00:15:59.798 I'll try to rotate it this way 249 00:16:00.580 --> 00:16:03.336 I'll tilt it this much, toward the right 250 00:16:04.385 --> 00:16:06.230 Then play it, and see what happens 251 00:16:07.260 --> 00:16:07.927 If you look 252 00:16:11.459 --> 00:16:14.506 You can see it moving in the diagonal direction 253 00:16:14.665 --> 00:16:17.637 So whether you're going to move it in the absolute direction 254 00:16:18.023 --> 00:16:20.614 Or move it in the relative direction 255 00:16:20.980 --> 00:16:25.197 Or rotate it instead of moving it, same thing with scaling 256 00:16:25.514 --> 00:16:29.978 There's the absolute concept and the relative concept for all 257 00:16:31.068 --> 00:16:34.491 So it will be good to make use of that 258 00:16:34.739 --> 00:16:36.700 We'll do it this way 259 00:16:36.700 --> 00:16:40.902 We'll use the Actor Forward Vector and make it move 260 00:16:42.377 --> 00:16:46.676 So there's a difference between the world direction and the local direction 261 00:16:47.280 --> 00:16:48.285 Should we leave this here? 262 00:16:53.027 --> 00:16:56.405 Then we'll come back here and delete the bullet 263 00:16:56.405 --> 00:16:58.865 We're not going to locate the bullet here 264 00:16:59.419 --> 00:17:01.854 But there's one thing you need to keep in mind 265 00:17:01.854 --> 00:17:06.637 We'll turn this back like this 266 00:17:07.835 --> 00:17:12.364 Let's say that we located in the same place as the character 267 00:17:12.859 --> 00:17:17.084 If we place this object on the start position of the player 268 00:17:17.936 --> 00:17:19.707 See what happens 269 00:17:20.875 --> 00:17:23.369 The bullet comes out, but the character doesn't appear 270 00:17:24.804 --> 00:17:28.174 This is the caution point. When we use player start 271 00:17:28.540 --> 00:17:32.173 And create the character automatically 272 00:17:32.371 --> 00:17:36.103 There can't be other objects in the place of the player 273 00:17:36.499 --> 00:17:38.115 It has to be out of the way 274 00:17:38.551 --> 00:17:42.415 It has to get out of the way, or place the object 275 00:17:42.415 --> 00:17:44.228 In another location 276 00:17:45.278 --> 00:17:47.553 Here, it says BAD size 277 00:17:48.523 --> 00:17:51.899 Do it like this, and it will properly 278 00:17:52.780 --> 00:17:54.864 Work properly like this 279 00:17:55.547 --> 00:17:57.798 This is one of the common mistakes 280 00:17:58.689 --> 00:18:02.488 So let's process it like this for now 281 00:18:04.968 --> 00:18:08.223 Then, when the character presses the button 282 00:18:08.223 --> 00:18:11.935 We want the bullet to appear when the player left-clicks the mouse 283 00:18:12.875 --> 00:18:16.743 In Unreal, the action of appearing is called Spawn 284 00:18:17.624 --> 00:18:19.122 Then let's try spawning 285 00:18:19.122 --> 00:18:20.398 Delete this first 286 00:18:24.018 --> 00:18:25.762 Save it first 287 00:18:26.880 --> 00:18:29.730 There's the character here, BP_Player 288 00:18:29.997 --> 00:18:33.577 It's here, and at the location of the player 289 00:18:33.973 --> 00:18:36.288 We want to make the bullet appear there 290 00:18:36.961 --> 00:18:39.222 Should we first make it appear once? 291 00:18:40.172 --> 00:18:45.124 How to do this, is first type Spawn here 292 00:18:45.659 --> 00:18:48.789 There's something called Spawn Actor From Class 293 00:18:50.997 --> 00:18:53.376 It's a node called Spawn Actor 294 00:18:54.089 --> 00:18:56.434 Using this, we can place the actor 295 00:18:56.810 --> 00:18:59.284 And locate it on the world level 296 00:18:59.897 --> 00:19:01.463 There's the Class part here 297 00:19:01.463 --> 00:19:07.695 This refers to what class the actor will appear under 298 00:19:08.180 --> 00:19:11.444 What we made is BP_Bullet, and it's here 299 00:19:11.444 --> 00:19:12.905 Let's choose this 300 00:19:13.459 --> 00:19:14.485 Then its name changes as well 301 00:19:14.594 --> 00:19:17.037 It becomes Spawn Actor BP_Bullet 302 00:19:18.978 --> 00:19:21.221 Then connect it like this 303 00:19:21.894 --> 00:19:23.291 Of course, we're not going to do it here 304 00:19:23.291 --> 00:19:25.602 Later, we're going to create an input 305 00:19:25.602 --> 00:19:28.248 And process it every time there's an input 306 00:19:28.248 --> 00:19:30.142 But we'll test it out here first 307 00:19:31.518 --> 00:19:35.326 Then compile it, and there will be an error 308 00:19:35.326 --> 00:19:38.354 That's because the transform of Spawn 309 00:19:39.680 --> 00:19:43.112 Is not properly set, that's what it's saying 310 00:19:44.499 --> 00:19:46.985 It's saying that we didn't enter the information for transform 311 00:19:48.352 --> 00:19:51.107 So we need to fill in the transform information 312 00:19:51.107 --> 00:19:53.096 We can make a new one 313 00:19:53.521 --> 00:19:57.027 Or we can refer to an existing one 314 00:19:57.512 --> 00:20:01.733 We can make it through Make Vector or Make Transform 315 00:20:02.020 --> 00:20:07.522 For example, we need to enter the location and rotation value 316 00:20:08.859 --> 00:20:13.047 If you see how the bullet rotated 317 00:20:15.196 --> 00:20:19.379 When we took out the bullet, we rotated it like this 318 00:20:22.283 --> 00:20:25.387 We took the green part and rotated it to change like this 319 00:20:25.387 --> 00:20:26.389 Then if you see here 320 00:20:28.557 --> 00:20:32.674 We can set the value to 0, 90, 0 321 00:20:33.288 --> 00:20:37.880 We just need to set the y to 90 and rotate it 322 00:20:38.029 --> 00:20:42.006 Then taking this, we can also enter the code manually 323 00:20:42.967 --> 00:20:44.152 Let's try that way first 324 00:20:44.578 --> 00:20:47.704 On the player, we're going to enter a value 325 00:20:47.704 --> 00:20:53.741 If you right-click the mouse on the Spawn Transform of Spawn Actor, 326 00:20:53.959 --> 00:20:58.224 Right-click on it, and we can split it 327 00:20:58.224 --> 00:20:59.537 We're dividing it 328 00:20:59.537 --> 00:21:02.964 Click it, and it divides into 3 329 00:21:03.568 --> 00:21:07.624 To combine again, use the Recombine menu 330 00:21:08.238 --> 00:21:10.774 So when you refer to these 331 00:21:10.774 --> 00:21:13.893 "Huh? It's the same Spawn Actor but the input pin looks different" 332 00:21:14.130 --> 00:21:16.373 That's what you may think but 333 00:21:16.680 --> 00:21:19.320 That's because splitting is possible 334 00:21:19.320 --> 00:21:22.674 These are all available for splitting and you can even go further 335 00:21:24.416 --> 00:21:27.208 Let's Recombine again 336 00:21:27.208 --> 00:21:32.104 I only want to edit the transform and the rotation part 337 00:21:32.104 --> 00:21:33.486 I won't touch the scale 338 00:21:34.308 --> 00:21:40.420 Then the location right now, for this object here 339 00:21:40.420 --> 00:21:44.632 We're going to place it 1m above this object 340 00:21:44.979 --> 00:21:47.978 Then the rotating direction, like how we've done it before 341 00:21:50.140 --> 00:21:53.714 Huh, did it get deleted? 342 00:21:54.159 --> 00:21:57.565 Anyways, we just need to rotate the y part 343 00:21:58.020 --> 00:22:01.023 So if that's how we want to do it 344 00:22:01.726 --> 00:22:05.639 Go to Player Event Graph, and since it's 1m above 345 00:22:07.601 --> 00:22:15.479 My current location, so on Get Actor Location, increase it by 1m 346 00:22:16.835 --> 00:22:24.440 Then we just need to add it by the vector of Get Actor Up Vector 347 00:22:24.609 --> 00:22:26.161 The Up Vector is 1m 348 00:22:26.161 --> 00:22:28.624 The basic length is 1 349 00:22:31.446 --> 00:22:33.648 Since it's 1, we need to multiply this by 100 350 00:22:33.915 --> 00:22:37.684 Multiply.. since this is 1, over here 351 00:22:38.219 --> 00:22:41.681 If we want to change it to Float, right-click here 352 00:22:41.879 --> 00:22:45.145 Right-click here and choose To Float 353 00:22:45.452 --> 00:22:47.864 Change it, and it will change like this 354 00:22:48.478 --> 00:22:52.254 Then multiply this by 100 and it will become 1m 355 00:22:53.046 --> 00:22:56.575 But it's 1m in the upward direction 356 00:22:56.575 --> 00:22:59.979 Add this and this together and it will become the new location 357 00:22:59.979 --> 00:23:04.595 Add, then connect it like this 358 00:23:05.021 --> 00:23:07.687 Rotation is about 90 359 00:23:08.390 --> 00:23:09.476 Should we do it like this? 360 00:23:11.347 --> 00:23:13.884 Then compile it, and there's no error anymore 361 00:23:14.825 --> 00:23:17.474 And play it, and a bullet 362 00:23:17.870 --> 00:23:20.578 Shoots out like this, right? 363 00:23:21.737 --> 00:23:24.248 But if we set the coordinate every time 364 00:23:24.485 --> 00:23:28.791 Through this calculating method, it will be pretty difficult, right? 365 00:23:28.791 --> 00:23:31.555 We might make mistakes too, so rather than this method 366 00:23:32.724 --> 00:23:35.538 This is an option, it's not mandatory 367 00:23:35.538 --> 00:23:38.546 Some may be more used to this calculation method 368 00:23:39.318 --> 00:23:40.414 Rather than this 369 00:23:41.067 --> 00:23:44.520 It's better to approach in a visual form 370 00:23:44.520 --> 00:23:47.026 We'll Recombine this 371 00:23:48.105 --> 00:23:53.085 On the component, we'll add an Arrow 372 00:23:55.498 --> 00:23:56.735 Add an Arrow 373 00:23:57.289 --> 00:24:00.666 Then when you go to Viewport, there's an arrow here 374 00:24:01.439 --> 00:24:03.827 The Arrow usually faces forward 375 00:24:03.827 --> 00:24:05.511 See the red arrow? 376 00:24:05.590 --> 00:24:06.780 Should we move it up a little? 377 00:24:07.473 --> 00:24:08.256 It looks like this 378 00:24:10.157 --> 00:24:12.795 We'll rotate the y 90 degrees 379 00:24:14.320 --> 00:24:15.088 Then it becomes like this 380 00:24:18.319 --> 00:24:20.404 We can make an arrow like this 381 00:24:21.345 --> 00:24:24.252 Locate the arrow at a good location 382 00:24:25.579 --> 00:24:27.037 Like this 383 00:24:30.099 --> 00:24:32.577 Compile it, then come over here 384 00:24:32.577 --> 00:24:35.026 Take the Arrow and bring it here 385 00:24:36.917 --> 00:24:48.635 And when we search Get Transform on the Arrow, many things pop up 386 00:24:49.189 --> 00:24:52.441 There's Relative Transform here 387 00:24:52.441 --> 00:24:54.460 There's Socket Transform, etc 388 00:24:54.460 --> 00:24:55.802 See the World Transform? 389 00:24:56.347 --> 00:24:57.322 We're going to use this 390 00:24:57.896 --> 00:25:01.478 Bring the World Transform and insert it right away 391 00:25:04.244 --> 00:25:06.471 Then after this, compile it 392 00:25:06.471 --> 00:25:10.391 Here, there's Collision Handling Override 393 00:25:10.391 --> 00:25:12.798 It's in Default, but open it up 394 00:25:13.442 --> 00:25:17.031 Always Spawn, Ignore Collisions 395 00:25:17.387 --> 00:25:23.440 Try to adjust location, but always spawn 396 00:25:23.440 --> 00:25:24.895 There are options like this 397 00:25:24.895 --> 00:25:28.638 There's also try to adjust location, but don't spawn if still colliding 398 00:25:29.687 --> 00:25:31.517 You can try them out 399 00:25:31.794 --> 00:25:34.988 But it doesn't always work out 400 00:25:35.236 --> 00:25:37.829 So most of the time, just use 401 00:25:37.829 --> 00:25:41.001 Always Spawn, Ignore Collision as the best option 402 00:25:41.120 --> 00:25:43.341 We're trying to spawn anyways 403 00:25:44.173 --> 00:25:45.669 Let's set it like this 404 00:25:49.107 --> 00:25:53.918 Then play it, and it shoots out like this again 405 00:25:53.918 --> 00:25:54.794 It shoots out this way 406 00:25:54.794 --> 00:25:56.425 We don't need to set the direction 407 00:25:57.979 --> 00:26:00.074 The direction of the arrow is already rotated 408 00:26:00.381 --> 00:26:03.146 The direction and coordinates of this 409 00:26:03.929 --> 00:26:06.169 When the bullet is made 410 00:26:06.476 --> 00:26:08.535 The coordinates get entered automatically 411 00:26:08.980 --> 00:26:12.349 That's a simple way to set it up 412 00:26:15.118 --> 00:26:19.381 Then let's change it so that we can fire it with a button 413 00:26:20.232 --> 00:26:24.861 Go to Project Settings, and Input 414 00:26:24.864 --> 00:26:26.369 It's here 415 00:26:26.931 --> 00:26:28.968 We're performing an action this time 416 00:26:28.968 --> 00:26:31.928 When we perform the action of left-clicking the mouse 417 00:26:32.245 --> 00:26:34.292 The bullet is going to appear like this 418 00:26:34.500 --> 00:26:38.597 Once the bullet appears, it travels toward on its own 419 00:26:39.339 --> 00:26:43.553 So we're going to create action, and axis is not an action 420 00:26:43.979 --> 00:26:45.042 You have to go to Action 421 00:26:45.042 --> 00:26:47.436 So we're going to add an action mapping 422 00:26:48.129 --> 00:26:49.898 Click the plus sign, and add it like this 423 00:26:50.878 --> 00:26:53.684 We're going to name it Fire 424 00:26:55.743 --> 00:26:56.986 And open this 425 00:26:57.887 --> 00:27:00.056 The key value will be Left Mouse Button 426 00:27:00.056 --> 00:27:02.600 You can set your own key 427 00:27:02.986 --> 00:27:05.048 I chose Left Mouse Button 428 00:27:06.048 --> 00:27:09.198 You can open this up 429 00:27:09.198 --> 00:27:11.073 And set it as Left Mouse 430 00:27:12.420 --> 00:27:14.652 Or you can press it yourself 431 00:27:15.770 --> 00:27:17.200 We'll set it like this 432 00:27:20.427 --> 00:27:22.483 Then it's the same method 433 00:27:22.948 --> 00:27:24.698 Go to Player 434 00:27:25.847 --> 00:27:28.270 We're going to disconnect this because it's not when it appears 435 00:27:28.736 --> 00:27:29.569 Disconnect it 436 00:27:32.077 --> 00:27:33.976 We created the action called Fire 437 00:27:33.976 --> 00:27:36.174 Then type Fire here 438 00:27:36.550 --> 00:27:39.315 There's Fire in the Action Event 439 00:27:39.721 --> 00:27:42.908 This appears here because we typed it as Fire 440 00:27:42.908 --> 00:27:47.847 If we put FireBullet instead of Fire 441 00:27:49.184 --> 00:27:54.076 Search it here, and it changes to FireBullet, right? 442 00:27:54.076 --> 00:27:57.458 The name that we type appears as is 443 00:27:58.092 --> 00:27:59.290 We'll change it back to Fire 444 00:28:02.289 --> 00:28:05.870 It will save automatically 445 00:28:06.474 --> 00:28:07.827 For this 446 00:28:09.935 --> 00:28:12.083 If you see here, Content 447 00:28:12.192 --> 00:28:16.978 Right-click and click Show in Explorer 448 00:28:17.780 --> 00:28:19.594 You can see the window here 449 00:28:19.594 --> 00:28:21.487 Go back one folder 450 00:28:21.834 --> 00:28:23.694 There's a folder called config 451 00:28:24.140 --> 00:28:30.205 And these contents are in the Defaultinput folder 452 00:28:30.819 --> 00:28:31.557 Shall we see? 453 00:28:34.540 --> 00:28:35.309 If you see here 454 00:28:43.196 --> 00:28:45.208 "Fire" appears here 455 00:28:45.564 --> 00:28:48.197 The things we entered are here 456 00:28:48.197 --> 00:28:51.095 On AxisMapping as well, there's Horizontal and Vertical 457 00:28:51.204 --> 00:28:53.994 They're entered here, right? 458 00:28:54.231 --> 00:29:01.061 So for Project Setting, even if we don't save it ourselves 459 00:29:01.061 --> 00:29:03.146 It becomes a file on its own 460 00:29:03.364 --> 00:29:05.175 We don't need to save it 461 00:29:05.175 --> 00:29:07.185 It saves automatically 462 00:29:08.026 --> 00:29:08.992 That's how it is 463 00:29:08.992 --> 00:29:12.615 Come back to play and create the Fire Event 464 00:29:13.209 --> 00:29:14.427 Put Fire 465 00:29:17.430 --> 00:29:22.069 For Action, there's the Pressed and Released concept 466 00:29:22.069 --> 00:29:26.114 It's the concept of pressed or released event 467 00:29:26.460 --> 00:29:29.596 So we're going to choose if it will happen when we press or when we release 468 00:29:30.576 --> 00:29:33.315 If we use this, we can make automatic firing 469 00:29:33.563 --> 00:29:35.108 And things like that 470 00:29:36.326 --> 00:29:37.428 Should we do it like this first? 471 00:29:37.567 --> 00:29:39.327 Pressed this way 472 00:29:41.020 --> 00:29:42.372 Like this, and compile 473 00:29:43.481 --> 00:29:48.465 Save it, and if we left-click 474 00:29:48.465 --> 00:29:51.606 The bullet fires as we press 475 00:29:52.358 --> 00:29:55.122 If you don't like the location of where the bullet is firing 476 00:29:55.320 --> 00:29:56.910 We'll edit it a little 477 00:29:56.910 --> 00:30:00.540 Change the location of the arrow a little bit 478 00:30:00.540 --> 00:30:01.698 You can move it down a little 479 00:30:03.780 --> 00:30:09.296 So that's how we can fire the bullet 480 00:30:10.021 --> 00:30:13.892 481 00:30:14.464 --> 00:30:16.611 This time, we're going to create the enemy 482 00:30:17.215 --> 00:30:21.379 Creating the enemy works the same way as the bullet 483 00:30:22.805 --> 00:30:26.325 To make the Enemy, we'll make another blueprint 484 00:30:27.236 --> 00:30:31.652 On the blueprint class, we're going to make BP_Actor, BP_Enemy 485 00:30:32.355 --> 00:30:35.279 Right-click the mouse, and go to blueprint class 486 00:30:35.962 --> 00:30:37.761 Then make the actor 487 00:30:39.266 --> 00:30:42.374 We'll name it BP_Enemy 488 00:30:43.562 --> 00:30:45.236 We're going to make the enemy 489 00:30:47.157 --> 00:30:51.282 Double-click, and place the enemy 490 00:30:51.540 --> 00:30:54.257 The enemy will also move forward 491 00:30:54.574 --> 00:30:57.380 Let's move forward first 492 00:30:58.756 --> 00:31:00.858 We need speed for this as well 493 00:31:01.006 --> 00:31:05.726 Enter Speed, and set it to Float 494 00:31:07.498 --> 00:31:11.343 It will be too difficult if the enemy is faster than the character 495 00:31:11.343 --> 00:31:14.316 So we'll make it the same speed as the character 496 00:31:14.504 --> 00:31:16.387 Enter the value of 500 497 00:31:22.845 --> 00:31:27.715 Then come to Event Graph and we'll move it 498 00:31:28.606 --> 00:31:31.964 Let's make the Enemy move forward first 499 00:31:32.459 --> 00:31:36.159 It's exactly the same as the bullet, right? 500 00:31:36.159 --> 00:31:38.207 It will move in the same method 501 00:31:40.537 --> 00:31:42.544 The bullet moved this way 502 00:31:43.752 --> 00:31:48.126 So the Enemy will be the same 503 00:31:49.067 --> 00:31:51.056 Then for this as well 504 00:31:53.099 --> 00:32:00.348 Use the equation P=P0 vt 505 00:32:05.281 --> 00:32:08.256 For the enemy as well, we'll move forward 506 00:32:09.296 --> 00:32:11.681 Not down, but forward 507 00:32:11.681 --> 00:32:13.178 We'll rotate it like this 508 00:32:15.380 --> 00:32:18.883 Later, we're not going to do it right now 509 00:32:18.883 --> 00:32:22.052 Later, we can move it forward with C 510 00:32:22.052 --> 00:32:25.038 Then make a creator so that it will appear 511 00:32:25.038 --> 00:32:27.107 In certain intervals 512 00:32:27.434 --> 00:32:29.094 Just like how the character makes the bullet 513 00:32:30.223 --> 00:32:33.623 Considering those, we'll also make this move forward 514 00:32:33.881 --> 00:32:35.118 We'll produce it that way 515 00:32:37.167 --> 00:32:38.784 We need to make direction first 516 00:32:38.784 --> 00:32:43.057 Forward means Get Vector Forward Vector 517 00:32:44.087 --> 00:32:47.425 Do this, and we can obtain the forward direction 518 00:32:48.444 --> 00:32:51.335 Right, Forward, Up 519 00:32:51.335 --> 00:32:53.666 These are all obtained through Forward, Right, Up here 520 00:32:54.716 --> 00:32:57.002 And we're going to move this 521 00:32:57.002 --> 00:33:02.173 On v, we need to multiply speed onto direction 522 00:33:02.540 --> 00:33:05.994 Multiply, and make two pins 523 00:33:05.994 --> 00:33:09.895 Make one first, set it to Float, then we'll add another pin 524 00:33:10.628 --> 00:33:12.871 Enter Speed as is 525 00:33:12.871 --> 00:33:17.105 Then we're going to enter delta second here. You see the Tick here? 526 00:33:17.750 --> 00:33:19.876 I'm going to set it aside 527 00:33:20.599 --> 00:33:23.417 On Event Tick, I'll move it like this 528 00:33:28.206 --> 00:33:32.225 Now we made v. We made vt 529 00:33:33.443 --> 00:33:36.473 Then we need to bring it 530 00:33:36.473 --> 00:33:41.391 Go to Get Actor Location, then bring P0 531 00:33:41.866 --> 00:33:43.357 It's the same method 532 00:33:44.594 --> 00:33:47.050 Huh? Do we not Normalize here? 533 00:33:47.050 --> 00:33:49.850 Why? The length of the forward vector is 1 534 00:33:49.850 --> 00:33:52.144 It's an already normalized vector with the length of 1 535 00:33:52.579 --> 00:33:54.425 You don't need to normalize 536 00:33:55.703 --> 00:33:59.797 So add these together like this, right? 537 00:33:59.995 --> 00:34:07.118 Do or Add, then put Set Vector Location 538 00:34:13.751 --> 00:34:15.719 Enter this value into New Location 539 00:34:16.076 --> 00:34:18.607 Then of course, we need to connect the pins 540 00:34:19.260 --> 00:34:21.206 That's how it will move 541 00:34:21.463 --> 00:34:22.538 Compile it 542 00:34:25.696 --> 00:34:27.588 Should we place it now? 543 00:34:28.548 --> 00:34:31.416 We're going to drag it and place it here 544 00:34:31.416 --> 00:34:33.013 Oh I didn't make its outer look 545 00:34:33.577 --> 00:34:37.565 Let's make the outer look of the enemy 546 00:34:37.565 --> 00:34:38.988 We'll make it into a box 547 00:34:38.988 --> 00:34:42.792 Click Add, and add Cube 548 00:34:44.089 --> 00:34:45.427 We'll use the enemy as is 549 00:34:48.818 --> 00:34:50.521 Compile, and now you can see the enemy 550 00:34:51.224 --> 00:34:55.384 Set the location. Should we place it above? 551 00:34:56.780 --> 00:35:00.529 Play it, and it looks like this 552 00:35:01.460 --> 00:35:03.615 We didn't rotate it, so it's probably moving forward 553 00:35:04.249 --> 00:35:06.474 The character is too centered 554 00:35:06.474 --> 00:35:09.255 Let's place the character a little lower 555 00:35:10.057 --> 00:35:13.029 We'll lower the Player Start 556 00:35:14.871 --> 00:35:17.637 Raise this a little, and now we need to rotate it 557 00:35:18.558 --> 00:35:21.919 It's moving forward, so rotate it this way 558 00:35:33.637 --> 00:35:34.320 Like this 559 00:35:37.517 --> 00:35:38.650 I think that's good 560 00:35:38.650 --> 00:35:43.914 Z is upward, and since this is right, this part will become the front 561 00:35:44.300 --> 00:35:46.006 Let's move it to the side a little 562 00:35:46.273 --> 00:35:49.008 Play it, and you can see it moving forward 563 00:35:51.325 --> 00:35:53.682 Then let's make it so that 564 00:35:54.088 --> 00:35:56.421 It moves toward the direction of the character 565 00:35:58.213 --> 00:36:00.627 Let me explain vector a little more 566 00:36:03.508 --> 00:36:06.758 We added vectors before, but now 567 00:36:09.419 --> 00:36:11.499 Let's look into subtraction of vectors 568 00:36:12.192 --> 00:36:15.827 For example, there's a vector that looks like this 569 00:36:17.738 --> 00:36:18.744 Let's call it vector A 570 00:36:19.487 --> 00:36:20.890 Then there's a vector that looks like this 571 00:36:21.237 --> 00:36:22.167 We'll call it vector B 572 00:36:23.157 --> 00:36:25.321 Then what we want to do 573 00:36:25.321 --> 00:36:29.577 The end of this vector is ultimately its location 574 00:36:30.498 --> 00:36:32.635 We want to make a vector that looks like this 575 00:36:32.635 --> 00:36:35.449 That's how B will move toward A 576 00:36:36.776 --> 00:36:39.718 So that's what we'll talk about 577 00:36:40.867 --> 00:36:42.468 If we call this vector C 578 00:36:43.963 --> 00:36:48.884 Vector C is A subtracted by B 579 00:36:50.844 --> 00:36:52.333 Then we can make vector C 580 00:36:52.897 --> 00:36:53.855 These are all vectors 581 00:36:56.073 --> 00:37:01.953 If we change the sign of vectors, it becomes the opposite direction 582 00:37:02.537 --> 00:37:03.808 What is means, is that 583 00:37:07.139 --> 00:37:10.912 If we want to make a vector that looks like this 584 00:37:12.041 --> 00:37:14.380 This will be -vector B 585 00:37:16.043 --> 00:37:18.464 Then should we add this and this together? 586 00:37:19.127 --> 00:37:21.218 If we add these two 587 00:37:23.219 --> 00:37:26.883 This is the clone of -vector B 588 00:37:27.398 --> 00:37:30.051 And a clone of vector A 589 00:37:30.556 --> 00:37:32.083 This vector will be created 590 00:37:33.340 --> 00:37:37.075 If you look here, these two vectors are the same 591 00:37:38.372 --> 00:37:40.542 This is possible because 592 00:37:42.315 --> 00:37:44.280 This works for vectors 593 00:37:44.280 --> 00:37:49.249 It's the same thing as Vector A plus negative Vector B 594 00:37:52.600 --> 00:37:58.038 Subtracting a vector is the same thing as 595 00:37:58.830 --> 00:38:01.107 Adding a negative vector 596 00:38:01.998 --> 00:38:03.482 This is the same as vector C 597 00:38:04.858 --> 00:38:05.741 We can do this 598 00:38:06.305 --> 00:38:08.756 To put it in an easier way 599 00:38:08.756 --> 00:38:11.369 If vector A is our target 600 00:38:13.689 --> 00:38:17.905 Target subtracted by my location is 601 00:38:17.905 --> 00:38:19.488 Gives vector that looks like this 602 00:38:21.913 --> 00:38:25.180 So the subtraction of vectors is usually used 603 00:38:25.427 --> 00:38:30.779 To determine the direction that I want to face 604 00:38:31.541 --> 00:38:35.551 Using this, let's say that the enemy is here 605 00:38:35.551 --> 00:38:39.956 And the character is here, and we want a vector that looks like this 606 00:38:40.461 --> 00:38:42.908 And for this vector 607 00:38:43.997 --> 00:38:46.693 The length of the vector may not be 1 608 00:38:46.693 --> 00:38:47.659 It may be far 609 00:38:47.659 --> 00:38:51.250 Let's say the distance between these two objects is 100 m 610 00:38:51.913 --> 00:38:53.941 Then the magnitude of this vector will be 100 m 611 00:38:55.060 --> 00:38:56.732 Then after this step 612 00:38:56.732 --> 00:38:58.828 We have to normalize it 613 00:39:01.877 --> 00:39:06.617 Using this concept, we'll move it towards the character 614 00:39:06.766 --> 00:39:08.270 Let's try it 615 00:39:09.488 --> 00:39:12.686 Go to Enemy, and go to Event Graph 616 00:39:13.538 --> 00:39:15.995 Then the direction is this 617 00:39:17.768 --> 00:39:20.945 We're going to set the direction of when it appears 618 00:39:21.192 --> 00:39:25.432 Set the direction at BeginPlay 619 00:39:26.154 --> 00:39:29.094 And on Tick, we want to make it continue moving in that direction 620 00:39:29.946 --> 00:39:34.447 Then these two events can't connect, right? 621 00:39:34.675 --> 00:39:38.823 So we need to understand these two as separate spaces 622 00:39:39.229 --> 00:39:43.015 We want to share the information between two separate spaces 623 00:39:43.836 --> 00:39:47.147 We can do this by creating a variable 624 00:39:48.394 --> 00:39:52.655 Create a variable, enter the value for that variable at BeginPlay 625 00:39:52.962 --> 00:39:56.575 Then use that variable value on Tick 626 00:39:57.318 --> 00:40:02.139 That way, we can share the same information between two spaces 627 00:40:02.693 --> 00:40:04.961 So we'll make a variable here 628 00:40:05.120 --> 00:40:09.854 We're going to set it to Vector 629 00:40:10.230 --> 00:40:11.538 Its name is Direction 630 00:40:15.926 --> 00:40:17.878 If we carry on the existing one 631 00:40:17.987 --> 00:40:20.211 We just need to set the Direction 632 00:40:21.716 --> 00:40:24.028 And bring this as is 633 00:40:25.562 --> 00:40:26.572 Disconnect this 634 00:40:27.998 --> 00:40:31.064 This way, the Actor Forward Vector is set 635 00:40:31.529 --> 00:40:35.399 Then it can move towards the direction of Direction 636 00:40:37.969 --> 00:40:40.781 So as long as we just change this Direction 637 00:40:40.781 --> 00:40:42.327 It will move in that direction 638 00:40:44.508 --> 00:40:47.640 So separate it, then bring it 639 00:40:48.294 --> 00:40:49.607 What we want to do, is this 640 00:40:51.399 --> 00:40:54.072 Let's try probability 641 00:40:54.547 --> 00:41:01.647 So 30% of the time, go towards the player 642 00:41:03.419 --> 00:41:06.449 And for the rest, go forward 643 00:41:09.998 --> 00:41:11.219 We want to process it like this 644 00:41:13.758 --> 00:41:17.376 Then these will become the other percentage 645 00:41:17.376 --> 00:41:20.818 Then it will be 70%. 30% and 70% 646 00:41:23.739 --> 00:41:25.866 Separate them like this 647 00:41:26.589 --> 00:41:27.528 Should we place them on top of each other? 648 00:41:31.917 --> 00:41:33.277 Then we need to make probability 649 00:41:33.277 --> 00:41:34.778 How to we make probabilities? 650 00:41:35.599 --> 00:41:39.589 We usually think of dices for probability 651 00:41:40.500 --> 00:41:43.434 Let's say there's a dice like this. A cube 652 00:41:45.018 --> 00:41:46.167 It has six sides 653 00:41:47.088 --> 00:41:51.009 If there's 1 here, there's a 5 on the back 654 00:41:51.009 --> 00:41:55.686 If there's a 2 here, the bottom is 4, is it right? 655 00:41:56.359 --> 00:41:57.780 Is it 1 and 6? 7? 656 00:41:57.780 --> 00:42:00.806 There's 6 across from 1, 5 across from 2 657 00:42:01.459 --> 00:42:02.659 This is how it goes 658 00:42:03.728 --> 00:42:07.870 What the probability of rolling a 1? 659 00:42:14.381 --> 00:42:16.802 It's 1/6 chance, because it's one side out of six 660 00:42:17.109 --> 00:42:21.033 Then the probability of rolling a 2 is also 1/6 chance 661 00:42:21.459 --> 00:42:24.611 2 also takes up only one side 662 00:42:24.938 --> 00:42:26.064 This is probability 663 00:42:26.292 --> 00:42:30.557 Then what's the probability of rolling less than 2? 664 00:42:31.686 --> 00:42:35.929 Probability of less than 2? 665 00:42:39.800 --> 00:42:41.528 Then it becomes 2/6 chance 666 00:42:43.771 --> 00:42:45.231 Oh is it 1/6? 667 00:42:45.360 --> 00:42:47.407 Then should we say less than 3? 668 00:42:48.110 --> 00:42:50.363 Probability of less than 3 is 2/6 669 00:42:50.660 --> 00:42:53.578 Because there are two: 1 and 2 670 00:42:55.598 --> 00:42:57.853 Then it reduces to 1/3 671 00:42:58.427 --> 00:43:02.971 We're going to make probability like this, and it's going to be 30% 672 00:43:03.120 --> 00:43:04.083 What does this mean? 673 00:43:04.371 --> 00:43:06.774 30 times out of 100 674 00:43:08.071 --> 00:43:12.028 So probability has a range 675 00:43:13.988 --> 00:43:17.182 For example, if there's 0 to 100, then 99 will be the range 676 00:43:17.559 --> 00:43:19.151 We can also say 1 to 100 677 00:43:19.784 --> 00:43:25.990 But 0 to 29 is 30 numbers, right? 678 00:43:25.990 --> 00:43:28.832 Less than 30, right? 679 00:43:28.832 --> 00:43:31.927 When one is pulled out from 100 of them 680 00:43:31.927 --> 00:43:35.040 The probability of it being less than 30 is 30% 681 00:43:36.238 --> 00:43:38.574 That's how we're going to process it 682 00:43:39.495 --> 00:43:42.557 Then we need to concept of random, right? 683 00:43:42.894 --> 00:43:48.283 Random Range 684 00:43:48.729 --> 00:43:50.804 Is it Random Range? Like this? 685 00:43:51.170 --> 00:43:53.899 If you see here, there's Integer and there's Float 686 00:43:53.899 --> 00:43:57.701 Float is usually 0 to 1, right? 687 00:43:57.701 --> 00:43:59.524 Something like 0.1 688 00:43:59.524 --> 00:44:01.444 This is used for those 689 00:44:02.009 --> 00:44:03.107 But Integer is used often as well 690 00:44:03.107 --> 00:44:04.684 Let's try Integer 691 00:44:05.288 --> 00:44:09.533 For integer, 0 to 99 right? 692 00:44:09.751 --> 00:44:11.721 Hover the mouse on top 693 00:44:12.582 --> 00:44:15.214 And if you look at Min and Max 694 00:44:15.402 --> 00:44:18.789 Greater than or equal to Min, Less than or equal to Max 695 00:44:18.789 --> 00:44:21.762 Then that means it's including Min and Max values 696 00:44:22.296 --> 00:44:24.755 Then we can just set it from 0 to 99, right? 697 00:44:27.320 --> 00:44:29.294 Then it becomes 100 of them 698 00:44:29.502 --> 00:44:34.506 Then if it's less than or greater than 699 00:44:34.773 --> 00:44:35.872 Then it will be like this, right? 700 00:44:35.872 --> 00:44:42.699 For greater than 70, it will be 71 to 99, right? 701 00:44:42.699 --> 00:44:44.067 Or 70 to 99, right? 702 00:44:44.067 --> 00:44:47.002 That will work, but isn't it easier to start from the minimum? 703 00:44:47.161 --> 00:44:51.169 So less than 30 is 0 to 29, so there's 30 of them 704 00:44:51.169 --> 00:44:52.935 We can make probability like this 705 00:44:53.321 --> 00:44:58.217 So if it's less than 30, then Branch 706 00:44:59.979 --> 00:45:01.660 Or there's also a shortcut key 707 00:45:01.660 --> 00:45:03.392 Press B and click, then Branch appears 708 00:45:04.491 --> 00:45:06.283 Should we use shortcuts? 709 00:45:07.738 --> 00:45:09.464 Then this needs to be pulled over as well 710 00:45:09.464 --> 00:45:12.032 Then now we made probability 711 00:45:12.497 --> 00:45:17.486 True for 30% of the time, False for the rest 712 00:45:19.140 --> 00:45:23.595 These are the other percentage, so these will become the False part 713 00:45:25.377 --> 00:45:27.970 Then for True 714 00:45:27.970 --> 00:45:31.056 Earlier, we made direction by doing target subtracted by v 715 00:45:31.442 --> 00:45:33.606 So find the character 716 00:45:33.606 --> 00:45:36.213 Subtract my location from the location of the character 717 00:45:36.550 --> 00:45:39.345 Create the direction, normalize it 718 00:45:39.632 --> 00:45:41.476 Then enter this into direction 719 00:45:43.406 --> 00:45:44.339 Let's try that 720 00:45:44.755 --> 00:45:47.088 This is 30% of the time, towards the player 721 00:45:48.493 --> 00:45:51.246 We need to find the player first 722 00:45:52.166 --> 00:45:55.793 There are various ways 723 00:45:55.793 --> 00:45:56.906 We can do this 724 00:45:56.906 --> 00:46:00.649 Normally, when looking for Actors on the level 725 00:46:00.649 --> 00:46:04.981 There's a node called Get Actor of Class 726 00:46:05.466 --> 00:46:11.541 Using this node, our character is BP_Player 727 00:46:11.659 --> 00:46:13.216 We can find it like this 728 00:46:13.216 --> 00:46:14.697 This is one method 729 00:46:15.162 --> 00:46:19.941 Or we can use Possess 730 00:46:20.149 --> 00:46:25.028 The player is possessing the pawn, right? 731 00:46:25.196 --> 00:46:30.788 For those instances, we can look for it through Get Player Pawn 732 00:46:31.937 --> 00:46:36.338 The Pawn that player 0 is possessing 733 00:46:36.338 --> 00:46:38.506 You can use either of those methods 734 00:46:39.258 --> 00:46:42.038 I'm going to try this 735 00:46:43.176 --> 00:46:45.740 I can use this, but I'll use this for now 736 00:46:46.681 --> 00:46:48.021 You can choose either one 737 00:46:48.941 --> 00:46:51.765 Bring the Pawn that player 0 is possessing 738 00:46:51.765 --> 00:46:56.736 And bring its location through Get Actor Location 739 00:46:57.300 --> 00:46:58.804 Then this is Vector right? 740 00:46:59.408 --> 00:47:01.001 The Return Value is at Vector 741 00:47:01.427 --> 00:47:04.764 So we can obtain the world coordinates of this Actor 742 00:47:05.189 --> 00:47:06.331 World location 743 00:47:06.866 --> 00:47:09.297 Then we also need to bring My Location 744 00:47:09.297 --> 00:47:13.899 Use the Get Actor Location as well 745 00:47:13.899 --> 00:47:15.647 Then the name is the same 746 00:47:16.151 --> 00:47:17.571 But the target is different 747 00:47:17.789 --> 00:47:19.438 Self is mine 748 00:47:19.903 --> 00:47:23.246 The other target is this, right? 749 00:47:23.869 --> 00:47:27.810 So you have to watch for the target 750 00:47:29.008 --> 00:47:32.474 So target subtracted by v 751 00:47:34.157 --> 00:47:36.565 Subtract, and subtract it like this 752 00:47:36.793 --> 00:47:40.629 Then this becomes the direction that I'll face 753 00:47:43.204 --> 00:47:45.260 But as mentioned earlier 754 00:47:45.914 --> 00:47:48.661 My, and by me, I mean the Enemy 755 00:47:48.661 --> 00:47:53.867 If the distance of the Enemy is greater than 1 756 00:47:53.867 --> 00:47:56.432 Then the size of this vector becomes greater than 1 757 00:47:56.907 --> 00:48:00.197 So change the value to 1 through normalizing 758 00:48:00.197 --> 00:48:02.790 We'll make it into a normalized vector 759 00:48:03.780 --> 00:48:06.387 So Normalize 760 00:48:09.296 --> 00:48:12.637 Make the Normalize Vector 761 00:48:15.127 --> 00:48:16.841 This is the error range 762 00:48:16.841 --> 00:48:20.924 These are all ultimately Float types 763 00:48:22.052 --> 00:48:26.010 If you have time, search up Floating point operation 764 00:48:27.129 --> 00:48:31.171 There are rules for how the computer performs Floating point operations 765 00:48:31.459 --> 00:48:34.083 There are some errors for this 766 00:48:34.083 --> 00:48:36.665 And we're talking about the error range for this 767 00:48:37.150 --> 00:48:38.539 So for example, it's like this 768 00:48:38.727 --> 00:48:42.501 1 is the same as 0.9999 769 00:48:42.501 --> 00:48:45.234 That much of an error is allowed 770 00:48:46.779 --> 00:48:50.580 So make the direction, and set this direction 771 00:48:50.580 --> 00:48:52.788 Go to Direction, and Set 772 00:48:55.540 --> 00:48:59.322 So when it's True, it connects this way 773 00:48:59.797 --> 00:49:05.323 So randomly, it either goes toward the character or forward 774 00:49:05.530 --> 00:49:07.552 That's how it will move 775 00:49:08.443 --> 00:49:10.434 Compile it, and let's see the results 776 00:49:12.384 --> 00:49:15.768 We need to try multiple times because it's a 30% chance 777 00:49:15.768 --> 00:49:20.879 It comes this way once, or it goes forward like this 778 00:49:22.354 --> 00:49:24.618 Using Random like this 779 00:49:24.618 --> 00:49:27.798 We've learned that we can create probability 780 00:49:31.182 --> 00:49:36.808 Like this, we created the bullet and enemy actors 781 00:49:38.699 --> 00:49:42.085 Let's summarize the content we learned today 782 00:49:42.873 --> 00:49:44.451 Creating and firing the bullet Creating and moving the bullet Create a new blueprint file BP_Bullet using Actor class as the parent class 783 00:49:44.451 --> 00:49:45.765 Use the Get Actor Forward Vector node to make the bullet to fire towards the forward direction Create the Speed variable of Float to set the speed of the bullet 784 00:49:45.765 --> 00:49:47.110 Use the transform equation P=P0 vt to move Bullet Firing Input Key Binding Add Action Mappings on the Project Setting Input Tab then create the InputAction Fire node in the graph panel 785 00:49:47.110 --> 00:49:48.360 To create the bullet with a key, connect the Spawn Actor From Class node 786 00:49:48.360 --> 00:49:49.655 Add the Arrow component on the Components panel to set the location and direction of the bullet Connect the world transform of the Arrow component to the transform of the bullet 787 00:49:49.655 --> 00:49:52.477 Creating the enemy Enemy creation Create a new blueprint file BP_Enemy that uses Actor class as the parent class Connect the node so that it move toward the forward direction 788 00:49:52.477 --> 00:49:55.159 Moving the enemy Use the same method as moving the bullet 789 00:49:55.159 --> 00:49:57.546 To move it towards the player, obtain the direction vector by subtracting the enemy vector from the player vector then connect the normalized direction vector of the enemy to Direction