WEBVTT 1 00:00:05.623 --> 00:00:09.632 Game Advanced Prototype 2 2 00:00:09.632 --> 00:00:12.098 GCC Academy 3 00:00:27.786 --> 00:00:28.686 Hello 4 00:00:28.686 --> 00:00:31.733 I'm Youngho Lee, and I'll be leading the lecture on creating shooting games 5 00:00:31.733 --> 00:00:33.183 In this lesson 6 00:00:33.183 --> 00:00:36.772 we'll cover the second part of the prototype 7 00:00:36.772 --> 00:00:39.972 First, we'll understand vectors and use them 8 00:00:39.972 --> 00:00:44.723 to move the player based on the uniform motion equation 9 00:00:44.723 --> 00:00:49.020 Then, we'll implement movement according to user input 10 00:00:50.400 --> 00:00:54.221 Understanding Vector 11 00:00:54.544 --> 00:00:58.762 Let's start by understanding vectors 12 00:00:58.762 --> 00:01:02.238 First, I'll create a simple sample code 13 00:01:02.238 --> 00:01:04.985 We'll write code where 14 00:01:04.985 --> 00:01:07.027 the player keeps moving to the right 15 00:01:08.975 --> 00:01:14.891 To achieve continuous movement to the right 16 00:01:14.891 --> 00:01:17.624 We'll use the following code 17 00:01:21.069 --> 00:01:22.841 Transform 18 00:01:24.544 --> 00:01:27.725 Translate 19 00:01:31.246 --> 00:01:41.185 Vector3.right* 5* Time. deltaTime 20 00:01:41.185 --> 00:01:44.285 I'll write this down 21 00:01:44.285 --> 00:01:46.983 By doing this, we're implementing the idea of the player 22 00:01:46.983 --> 00:01:48.544 moving continuously to the right 23 00:01:48.544 --> 00:01:51.247 We put the content in Korean first 24 00:01:51.247 --> 00:01:52.547 Now, if you look at this code 25 00:01:52.547 --> 00:01:55.762 you'll notice it's placed in the Update function rather than Start 26 00:01:55.762 --> 00:01:59.112 The reason is that the code needs to be in the Update function 27 00:01:59.112 --> 00:02:01.062 when you want something to keep happening 28 00:02:01.062 --> 00:02:04.277 while the game is running 29 00:02:04.277 --> 00:02:06.727 After saving this 30 00:02:06.727 --> 00:02:09.762 let's go ahead and test it out 31 00:02:09.762 --> 00:02:10.862 When you press the play button 32 00:02:13.278 --> 00:02:15.416 You can see the player continuously moving to the right 33 00:02:18.208 --> 00:02:24.000 This is made possible by the line of code we just wrote is essential 34 00:02:24.000 --> 00:02:28.634 To grasp this fully, we need to explore a few concepts 35 00:02:28.634 --> 00:02:30.734 Let's start by looking into vectors 36 00:02:30.734 --> 00:02:33.822 and then dive deeper into the code 37 00:02:36.901 --> 00:02:41.505 First, what exactly is a vector? 38 00:02:41.505 --> 00:02:45.247 If you look at its structure, it's represented as an arrow 39 00:02:45.247 --> 00:02:48.663 This arrow has a body 40 00:02:48.663 --> 00:02:50.594 I'll call here body, and this tail 41 00:02:50.594 --> 00:02:53.832 I'll say "tail," and a "head" 42 00:02:53.832 --> 00:02:58.307 The blue part of the arrow represents its magnitude 43 00:02:58.307 --> 00:03:01.505 and the red arrowhead 44 00:03:01.505 --> 00:03:03.604 indicates its direction 45 00:03:06.396 --> 00:03:09.393 A vector is an element that combines 46 00:03:09.393 --> 00:03:11.455 these two components 47 00:03:11.455 --> 00:03:14.000 Magnitude and direction 48 00:03:14.000 --> 00:03:16.050 This one which always includes both 49 00:03:16.050 --> 00:03:17.386 We call it a vector 50 00:03:19.584 --> 00:03:22.041 Vectors play a crucial role 51 00:03:22.041 --> 00:03:23.911 when we want to express 52 00:03:23.911 --> 00:03:27.238 physical movement 53 00:03:27.238 --> 00:03:30.588 They're used for simple mechanics like moving objects 54 00:03:30.588 --> 00:03:32.525 Also 55 00:03:32.525 --> 00:03:37.911 Simulating interactions like light hitting a surface, bouncing off 56 00:03:37.911 --> 00:03:40.611 and reflecting 57 00:03:40.611 --> 00:03:43.000 All of these processes 58 00:03:43.000 --> 00:03:46.000 rely heavily on vectors 59 00:03:46.000 --> 00:03:48.150 For instance, if you look at the arrows 60 00:03:48.150 --> 00:03:51.782 on the screen representing the direction of light 61 00:03:51.782 --> 00:03:54.396 They're vectors 62 00:03:54.396 --> 00:03:58.594 By understanding vectors thoroughly 63 00:03:58.594 --> 00:04:01.194 you'll gain a solid foundation 64 00:04:01.194 --> 00:04:03.000 for working with 65 00:04:03.000 --> 00:04:08.634 Unity to create games 66 00:04:08.634 --> 00:04:12.337 Now, let's take a closer look at the various characteristics of vectors 67 00:04:14.139 --> 00:04:17.168 Vectors are typically represented as arrows 68 00:04:17.168 --> 00:04:19.426 and they can undergo arithmetic operations 69 00:04:22.683 --> 00:04:24.842 These operations include 70 00:04:24.842 --> 00:04:28.970 addition, subtraction, multiplication, and division 71 00:04:28.970 --> 00:04:31.366 Right? 72 00:04:31.366 --> 00:04:35.166 However, in the context of vectors 73 00:04:35.166 --> 00:04:36.673 we primarily use multiplication and division 74 00:04:36.673 --> 00:04:38.594 When it comes to multiplication, there are two main types 75 00:04:38.594 --> 00:04:40.744 Dot Product 76 00:04:40.744 --> 00:04:43.604 It is represented with a dot and used for certain calculations 77 00:04:43.604 --> 00:04:46.704 Then, Cross Product 78 00:04:46.704 --> 00:04:50.614 It's used like this 79 00:04:50.614 --> 00:04:53.485 Since it's a dot, we call it Dot Product 80 00:04:53.485 --> 00:04:56.435 and this one with "x" symbol 81 00:04:56.435 --> 00:04:58.386 So we call this Cross Product 82 00:04:58.386 --> 00:05:01.486 In Korean, the dot product is called 'naejeok' 83 00:05:01.486 --> 00:05:05.287 and this is called 'woejeok' 84 00:05:05.287 --> 00:05:08.277 What we have to focus on is 85 00:05:08.277 --> 00:05:12.000 addition and subtraction 86 00:05:12.000 --> 00:05:14.118 These are really important 87 00:05:14.118 --> 00:05:15.406 to do the work 88 00:05:15.406 --> 00:05:18.606 And these two 89 00:05:18.606 --> 00:05:20.832 are used variously 90 00:05:20.832 --> 00:05:24.982 The dot product is a multiplication operation 91 00:05:24.982 --> 00:05:26.822 between two vectors 92 00:05:26.822 --> 00:05:29.931 that results in a single numerical value 93 00:05:29.931 --> 00:05:35.168 As we mentioned earlier, vectors consist of magnitude and direction 94 00:05:35.168 --> 00:05:36.668 The resulting value from a dot product 95 00:05:36.668 --> 00:05:39.861 is called a scalar 96 00:05:39.861 --> 00:05:42.851 A scalar 97 00:05:42.851 --> 00:05:46.701 When you perform a dot product operation on two vectors 98 00:05:46.701 --> 00:05:50.604 each defined by magnitude and direction 99 00:05:50.604 --> 00:05:53.535 you obtain a scalar value 100 00:05:53.535 --> 00:05:56.435 Next, this Cross Product, the outer product 101 00:05:56.435 --> 00:05:59.000 When you do the outer product of two vectors 102 00:05:59.000 --> 00:06:01.550 a vector perpendicular to these two vectors 103 00:06:01.550 --> 00:06:04.475 pops out 104 00:06:04.475 --> 00:06:07.574 We call this the outer product 105 00:06:07.574 --> 00:06:09.647 The two vectors are used for very important roles 106 00:06:09.647 --> 00:06:12.406 depending on their purpose 107 00:06:12.406 --> 00:06:14.056 This time, we will learn about 108 00:06:14.056 --> 00:06:17.000 addition and subtraction 109 00:06:17.000 --> 00:06:23.188 Then, the important thing is how addition is used 110 00:06:23.188 --> 00:06:26.000 Let's assume that there are two vectors 111 00:06:30.663 --> 00:06:32.258 Let's take a look 112 00:06:35.280 --> 00:06:36.880 Here is the vector of A 113 00:06:36.880 --> 00:06:39.440 and then here is the vector of b 114 00:06:39.440 --> 00:06:41.840 The vector of A can be placed here 115 00:06:41.840 --> 00:06:43.360 and on top of this 116 00:06:43.360 --> 00:06:47.920 This vector has a magnitude and a direction, right? 117 00:06:47.920 --> 00:06:52.600 In other words, it does not include a location 118 00:06:52.600 --> 00:06:54.950 Let’s think of vector A as wind 119 00:06:54.950 --> 00:06:58.379 The wind blows continuously 120 00:06:58.379 --> 00:07:00.429 It's blowing like this 121 00:07:00.429 --> 00:07:03.000 It doesn’t only blow 122 00:07:03.000 --> 00:07:05.500 between specific points 123 00:07:05.500 --> 00:07:08.560 When you open a window, how does the wind flow? 124 00:07:08.560 --> 00:07:10.281 It simply comes in 125 00:07:12.093 --> 00:07:13.510 regardless of its position 126 00:07:13.510 --> 00:07:16.860 When I'm there, the wind comes in like this 127 00:07:16.860 --> 00:07:20.880 So, it doesn't matter where it is located 128 00:07:20.880 --> 00:07:25.408 So whether you put it here or here 129 00:07:25.408 --> 00:07:27.560 it blows like this 130 00:07:27.560 --> 00:07:29.860 So, it doesn't matter 131 00:07:29.860 --> 00:07:34.748 if I put the position of A here, this vector of A, right? 132 00:07:34.748 --> 00:07:38.199 Now, let's imagine you press both the right arrow key 133 00:07:38.199 --> 00:07:41.559 and the up arrow key 134 00:07:41.559 --> 00:07:44.477 So what happens if the plane hits both 135 00:07:44.477 --> 00:07:46.199 at the same time? 136 00:07:46.199 --> 00:07:47.899 If you look at the last picture 137 00:07:47.899 --> 00:07:51.040 you can see that it has to go diagonally 138 00:07:51.040 --> 00:07:56.559 In other words, if you add the two vectors if you connect the endpoints like this 139 00:07:56.559 --> 00:07:58.409 you get a vector 140 00:07:58.409 --> 00:08:02.463 that points to the last two points 141 00:08:02.463 --> 00:08:05.760 Vector addition works like this 142 00:08:05.760 --> 00:08:08.410 It represents the sum of 143 00:08:08.410 --> 00:08:12.523 all forces acting on an object 144 00:08:14.199 --> 00:08:15.460 Let’s take an example 145 00:08:17.400 --> 00:08:19.751 Imagine we throw a ball 146 00:08:19.751 --> 00:08:22.905 Like this 147 00:08:22.905 --> 00:08:25.760 If we throw it 148 00:08:25.760 --> 00:08:29.960 will the ball 149 00:08:29.960 --> 00:08:32.120 fly infinitely in one direction?fly infinitely in one direction? 150 00:08:32.120 --> 00:08:35.519 Will it even go through the Earth? 151 00:08:35.519 --> 00:08:36.340 For real? 152 00:08:38.419 --> 00:08:42.039 No, it follows a curved path, a parabola 153 00:08:42.039 --> 00:08:43.960 and eventually falls to the ground, right? 154 00:08:43.960 --> 00:08:47.160 In a typical scenario, it will fall due to gravity pulling it downward 155 00:08:47.160 --> 00:08:49.240 Why? 156 00:08:49.240 --> 00:08:51.320 Because gravity acts 157 00:08:51.320 --> 00:08:53.880 How does it work? 158 00:08:53.880 --> 00:08:55.360 It acts downward 159 00:08:55.360 --> 00:08:57.810 So, if you add these two arrows 160 00:08:57.810 --> 00:09:00.800 It goes like this 161 00:09:00.800 --> 00:09:02.833 It doesn't happen like this 162 00:09:02.833 --> 00:09:06.679 Gravity gradually affects my force, so what happens? 163 00:09:06.679 --> 00:09:09.429 This one goes like this 164 00:09:09.429 --> 00:09:12.199 and it goes in a parabolic motion 165 00:09:12.199 --> 00:09:16.712 So vectors can express the sum of all forces 166 00:09:16.712 --> 00:09:20.000 when adding 167 00:09:20.000 --> 00:09:22.679 If the wind blows in the opposite direction like this 168 00:09:22.679 --> 00:09:24.479 And gravity is also at work 169 00:09:24.479 --> 00:09:28.929 If you add them all up, how do you think the ball will fly 170 00:09:28.929 --> 00:09:31.679 when the wind is very strong? 171 00:09:31.679 --> 00:09:34.029 It flies like this, and then, because of the wind 172 00:09:34.029 --> 00:09:37.355 it returns like this 173 00:09:37.355 --> 00:09:40.004 Right? You can direct it like this 174 00:09:42.360 --> 00:09:46.510 So the wind is this force 175 00:09:46.510 --> 00:09:47.960 the force we threw is this force 176 00:09:47.960 --> 00:09:50.110 and the gravity that falls down 177 00:09:50.110 --> 00:09:54.960 When you add all these up, the object's final position is determined 178 00:09:54.960 --> 00:09:58.455 When you add all these up, the object's final position is determined 179 00:09:58.455 --> 00:10:01.005 I think it would be good to know that addition 180 00:10:01.005 --> 00:10:02.240 is used for this purpose 181 00:10:02.240 --> 00:10:06.479 Representative games include baseball, golf 182 00:10:06.479 --> 00:10:09.529 and billiards 183 00:10:09.529 --> 00:10:11.633 You can think of all of these as using addition to this vector 184 00:10:14.138 --> 00:10:16.309 How do we use subtraction? 185 00:10:19.558 --> 00:10:23.726 In the end, subtraction is also a part of addition, right? 186 00:10:27.418 --> 00:10:32.680 If we have A, we can subtract it by adding its opposite 187 00:10:32.680 --> 00:10:34.639 So, while subtraction is technically an addition 188 00:10:34.639 --> 00:10:35.889 its purpose varies 189 00:10:35.889 --> 00:10:38.000 depending on how we use it 190 00:10:38.000 --> 00:10:40.600 Let's say we have vector A here and vector B here 191 00:10:40.600 --> 00:10:43.759 If we subtract A 192 00:10:43.759 --> 00:10:46.040 what happens? 193 00:10:46.040 --> 00:10:51.399 Interestingly, subtracting A flips its direction 194 00:10:51.399 --> 00:10:53.549 That's because 195 00:10:53.549 --> 00:10:57.200 When negative numbers and minuses are multiplied 196 00:10:57.200 --> 00:10:59.160 What happens when -1 is multiplied? 197 00:10:59.160 --> 00:11:01.660 That is, the direction of the vector can be changed 198 00:11:01.660 --> 00:11:03.279 Right? 199 00:11:03.279 --> 00:11:05.986 Now, if vector A points this way 200 00:11:05.986 --> 00:11:07.720 and vector B points this way 201 00:11:07.720 --> 00:11:09.870 how do we find 202 00:11:09.870 --> 00:11:12.612 the resultant vector, like in addition? 203 00:11:12.612 --> 00:11:15.600 The final vector would look like this 204 00:11:15.600 --> 00:11:21.650 B - A, how does it come out? 205 00:11:21.650 --> 00:11:23.279 It comes out like this 206 00:11:23.279 --> 00:11:25.760 How do you know this then? 207 00:11:25.760 --> 00:11:31.200 It's like A wants to move to B 208 00:11:31.200 --> 00:11:35.200 So, you can see vector subtraction like this 209 00:11:35.200 --> 00:11:37.040 How is it used? 210 00:11:37.040 --> 00:11:42.262 Imagine you are here, and your target is over there 211 00:11:44.559 --> 00:11:50.152 You want to go toward the target 212 00:11:50.152 --> 00:11:52.281 I want to go in the direction of the target like this 213 00:11:52.281 --> 00:11:57.200 So, our goal is to find this vector 214 00:11:57.200 --> 00:12:00.480 How do I do this? Where do I want to go? 215 00:12:00.480 --> 00:12:02.397 I want to go in the direction of the target 216 00:12:05.040 --> 00:12:07.391 Let's call this vector the direction 217 00:12:10.480 --> 00:12:14.079 So how do I find this Direction, this vector? 218 00:12:14.079 --> 00:12:16.979 It's Target - Me 219 00:12:16.979 --> 00:12:19.429 I find it like this when I want to 220 00:12:19.429 --> 00:12:20.959 go to the target 221 00:12:20.959 --> 00:12:23.159 Target - Me means 222 00:12:23.159 --> 00:12:26.509 I can see the vector from me 223 00:12:26.509 --> 00:12:27.790 to the target, the destination 224 00:12:29.686 --> 00:12:31.920 Okay? This is how I can find it 225 00:12:31.920 --> 00:12:34.320 Let's find out one more thing here 226 00:12:34.320 --> 00:12:36.799 Let me draw this on a graph 227 00:12:36.799 --> 00:12:40.299 Let's put it 228 00:12:40.299 --> 00:12:42.799 like this in rectangular coordinates 229 00:12:42.799 --> 00:12:45.043 Here's the X-axis, right? Here's the Y-axis 230 00:12:46.360 --> 00:12:49.519 It's like this 231 00:12:49.519 --> 00:12:53.027 Let's move it over here so that it's easier to see 232 00:12:55.839 --> 00:12:59.839 Then, if you look at it 233 00:12:59.839 --> 00:13:05.359 I'm here, and the target is at this point 234 00:13:05.359 --> 00:13:09.440 How about looking at the two positions like this? 235 00:13:09.440 --> 00:13:14.190 From here to this point 236 00:13:14.190 --> 00:13:16.640 let's call it x1 237 00:13:16.640 --> 00:13:20.239 Here's x, here's x1 238 00:13:20.239 --> 00:13:23.389 Then, at this point 239 00:13:23.389 --> 00:13:27.119 let's call this Y1 240 00:13:27.119 --> 00:13:31.519 In other words, let's say this vector is added 241 00:13:31.519 --> 00:13:33.869 If my position is at this point 242 00:13:33.869 --> 00:13:35.919 and if I add this vector to my position 243 00:13:35.919 --> 00:13:38.720 where am I ultimately? 244 00:13:38.720 --> 00:13:41.200 I'm at the target position 245 00:13:41.200 --> 00:13:43.983 Then, if I'm standing here 246 00:13:43.983 --> 00:13:49.433 and this standing character moves to that side 247 00:13:49.433 --> 00:13:50.640 if I add this vector 248 00:13:50.640 --> 00:13:53.839 it'll move like teleportation, right? 249 00:13:53.839 --> 00:13:56.559 This isn't the type of movement we want 250 00:13:56.559 --> 00:13:58.000 What do we want to do? 251 00:13:58.000 --> 00:14:02.399 I want to go like this at my speed 252 00:14:02.399 --> 00:14:04.320 In that direction 253 00:14:04.320 --> 00:14:08.216 Then, I told you that this vector 254 00:14:08.216 --> 00:14:11.279 comprises magnitude and direction 255 00:14:11.279 --> 00:14:13.929 Then I don't need this magnitude 256 00:14:13.929 --> 00:14:18.160 I just simply need this direction 257 00:14:18.160 --> 00:14:20.210 and I'm just going to move this character 258 00:14:20.210 --> 00:14:24.559 in this direction 259 00:14:24.559 --> 00:14:26.799 Then 260 00:14:26.799 --> 00:14:32.160 I said that it comprises magnitude and direction 261 00:14:32.160 --> 00:14:34.720 I wrote multiplication here 262 00:14:34.720 --> 00:14:37.760 At that time, I only needed direction 263 00:14:37.760 --> 00:14:41.200 So I'm going to have my movement speed 264 00:14:41.200 --> 00:14:43.839 I'm going to multiply my speed here 265 00:14:43.839 --> 00:14:46.539 Then the vector's magnitude 266 00:14:46.539 --> 00:14:49.426 doesn't simply becomes something 267 00:14:52.000 --> 00:14:53.559 But I want it to be like this 268 00:14:53.559 --> 00:14:57.720 So I want it to move this much at my speed 269 00:14:57.720 --> 00:15:02.370 Then, what if this vector we got by subtracting vectors 270 00:15:02.370 --> 00:15:04.689 becomes specific speed, it's my speed 271 00:15:04.689 --> 00:15:07.479 This is me 272 00:15:07.479 --> 00:15:09.779 Will only my speed and direction remain? 273 00:15:09.779 --> 00:15:11.512 What should this magnitude become? 274 00:15:11.512 --> 00:15:13.880 It should be 1 275 00:15:13.880 --> 00:15:18.120 So this action of making the magnitude of this vector 276 00:15:18.120 --> 00:15:20.748 this direction 277 00:15:20.748 --> 00:15:23.098 from Target - Me 1 278 00:15:23.098 --> 00:15:26.960 is called vector normalization 279 00:15:26.960 --> 00:15:30.325 In English, it's called Normalize 280 00:15:31.870 --> 00:15:34.119 That's what it means 281 00:15:34.119 --> 00:15:37.969 This is the action I take when I want to move at my speed 282 00:15:37.969 --> 00:15:39.559 with this vector 283 00:15:39.559 --> 00:15:42.039 that I got by subtracting vectors 284 00:15:42.039 --> 00:15:45.280 At this time, vector normalization is used 285 00:15:45.280 --> 00:15:50.159 Then you guys will make a game 286 00:15:50.159 --> 00:15:52.679 Let's say it's an MMORPG game 287 00:15:52.679 --> 00:15:57.280 I clicked here with the mouse pointer 288 00:15:57.280 --> 00:15:59.320 I clicked here like this 289 00:15:59.320 --> 00:16:01.970 Then, the character should stand here 290 00:16:01.970 --> 00:16:03.599 and move in this direction 291 00:16:03.599 --> 00:16:06.239 Then how do I do it? 292 00:16:06.239 --> 00:16:11.080 My position, the position of the target that the mouse clicked, will be found 293 00:16:11.080 --> 00:16:15.119 If I do Target - Me, this vector will be found 294 00:16:15.119 --> 00:16:18.280 Then I will move in this direction 295 00:16:18.280 --> 00:16:20.039 In something like an MMORPG 296 00:16:20.039 --> 00:16:21.828 Then, instead of just adding this vector 297 00:16:21.828 --> 00:16:24.531 you have to normalize it 298 00:16:24.531 --> 00:16:27.239 to make it fit into this vector 299 00:16:27.239 --> 00:16:30.320 In other words, if you make it into a normalized vector like this 300 00:16:30.320 --> 00:16:32.970 you can move in that direction 301 00:16:32.970 --> 00:16:34.719 at your speed 302 00:16:34.719 --> 00:16:36.960 This is called normalization 303 00:16:36.960 --> 00:16:39.060 So vectors are largely 304 00:16:39.060 --> 00:16:42.760 divided into addition, subtraction, inner product, and outer product 305 00:16:42.760 --> 00:16:45.410 but this time, we only looked at addition 306 00:16:45.410 --> 00:16:48.520 and subtraction 307 00:16:48.520 --> 00:16:56.559 Then, in this sentence we mentioned earlier 308 00:16:56.559 --> 00:16:59.359 in the part where the player goes to the right 309 00:16:59.359 --> 00:17:01.280 there's a part that says Right here 310 00:17:01.280 --> 00:17:02.930 This is a vector 311 00:17:02.930 --> 00:17:05.644 so it has the direction of the right side of the vector 312 00:17:08.080 --> 00:17:11.520 What is its size? It's 1 313 00:17:11.520 --> 00:17:14.159 What's the 5 at the end? 314 00:17:14.159 --> 00:17:16.599 That would be my movement speed 315 00:17:16.599 --> 00:17:19.149 The one behind, I'll talk about it again later 316 00:17:19.149 --> 00:17:23.520 is just the time used in uniform motion 317 00:17:23.520 --> 00:17:25.479 The time used in uniform motion 318 00:17:25.479 --> 00:17:26.520 So what? 319 00:17:26.520 --> 00:17:31.280 That's the vector I created 320 00:17:31.280 --> 00:17:33.931 And the one behind is the time multiplied 321 00:17:33.931 --> 00:17:37.911 Understanding Constant Velocity Motion Formula and Player Movement Creation 322 00:17:38.919 --> 00:17:42.219 Then, let's learn about the formulas 323 00:17:42.219 --> 00:17:45.039 for uniform motion 324 00:17:45.039 --> 00:17:50.400 If you look 325 00:17:50.400 --> 00:17:54.000 it's about Newton's kinematics 326 00:17:54.000 --> 00:17:58.280 The first part is P = P0 + vt 327 00:17:58.280 --> 00:18:00.799 v = v0 + at 328 00:18:00.799 --> 00:18:03.320 The third is F = ma 329 00:18:03.320 --> 00:18:04.440 It goes like this 330 00:18:04.440 --> 00:18:06.479 The last one is F = ma 331 00:18:06.479 --> 00:18:09.840 It's probably ingrained in your DNA 332 00:18:09.840 --> 00:18:11.039 What about F? 333 00:18:11.039 --> 00:18:14.430 I don't know where you use it, but ma? 334 00:18:14.430 --> 00:18:18.400 The part that comes out like this is where it says F = ma 335 00:18:18.400 --> 00:18:21.400 So when an object moves dynamically 336 00:18:21.400 --> 00:18:24.661 or becomes like this by kinematics 337 00:18:24.661 --> 00:18:28.039 These three formulas are used 338 00:18:28.039 --> 00:18:30.919 That's why the physics engine embedded in Unity 339 00:18:30.919 --> 00:18:32.669 also uses these formulas 340 00:18:32.669 --> 00:18:37.440 to implement the parts where objects move 341 00:18:37.440 --> 00:18:40.400 The first of these is the formula for uniform motion 342 00:18:40.400 --> 00:18:43.559 Let's say there's a person here 343 00:18:43.559 --> 00:18:47.400 You guys push them from behind 344 00:18:47.400 --> 00:18:50.799 You push them with a bang 345 00:18:50.799 --> 00:18:54.760 What happens to this person then? 346 00:18:54.760 --> 00:18:56.760 If you push them from behind 347 00:18:56.760 --> 00:19:02.520 they'll get pushed this way 348 00:19:02.520 --> 00:19:03.840 Of course 349 00:19:03.840 --> 00:19:06.760 At this time, the shape in which the object moves 350 00:19:06.760 --> 00:19:10.119 is created by this formula 351 00:19:10.119 --> 00:19:16.559 First, let's put P0 as the current position 352 00:19:16.559 --> 00:19:18.239 of this person 353 00:19:18.239 --> 00:19:19.080 This is the current position 354 00:19:19.080 --> 00:19:20.440 Position 355 00:19:20.440 --> 00:19:23.520 Next, this is my future position 356 00:19:23.520 --> 00:19:27.443 Let's put P 357 00:19:27.443 --> 00:19:29.095 Next, there's 358 00:19:29.095 --> 00:19:31.520 the direction that occurred when the user pushed from behind 359 00:19:31.520 --> 00:19:32.960 This is an arrow 360 00:19:32.960 --> 00:19:34.400 What do we call this? 361 00:19:34.400 --> 00:19:35.320 It's called a vector 362 00:19:35.320 --> 00:19:38.359 Let's put V, which stands for velocity 363 00:19:38.359 --> 00:19:39.919 Velocity, V 364 00:19:39.919 --> 00:19:42.640 This is a vector 365 00:19:42.640 --> 00:19:45.754 So, this person doesn't move instantly 366 00:19:45.754 --> 00:19:50.152 but moves gradually over time 367 00:19:50.152 --> 00:19:52.840 That's why there's a T at the end 368 00:19:52.840 --> 00:19:57.719 So they move over time 369 00:19:57.719 --> 00:20:00.799 Let's take a look at this again 370 00:20:00.799 --> 00:20:04.000 I pushed from behind 371 00:20:04.000 --> 00:20:04.760 Did you? 372 00:20:04.760 --> 00:20:08.589 When you push this, a force is applied 373 00:20:08.589 --> 00:20:10.479 A force is applied 374 00:20:10.479 --> 00:20:12.719 The one in front is called uniform motion 375 00:20:12.719 --> 00:20:14.880 The one behind is called uniformly accelerated motion 376 00:20:14.880 --> 00:20:15.799 The last one below 377 00:20:15.799 --> 00:20:18.719 the force goes up to F = ma 378 00:20:18.719 --> 00:20:20.960 This also goes like this 379 00:20:20.960 --> 00:20:24.559 Now, what is A here? 380 00:20:24.559 --> 00:20:27.919 This part affects the current position 381 00:20:27.919 --> 00:20:28.760 which is velocity 382 00:20:28.760 --> 00:20:32.200 Velocity 383 00:20:32.200 --> 00:20:35.594 a is acceleration that affects velocity 384 00:20:39.039 --> 00:20:39.679 Okay? 385 00:20:39.679 --> 00:20:41.119 Here, m is mass 386 00:20:41.119 --> 00:20:43.719 The mass of the object 387 00:20:43.719 --> 00:20:49.799 So, let's put mass as 1 here 388 00:20:49.799 --> 00:20:52.359 Then what will F be? 389 00:20:52.359 --> 00:20:54.539 It will be a, right? 390 00:20:54.539 --> 00:20:57.080 I pushed from behind with force 391 00:20:57.080 --> 00:20:58.919 What happens then? 392 00:20:58.919 --> 00:21:01.435 a is created 393 00:21:01.435 --> 00:21:02.799 a is created 394 00:21:02.799 --> 00:21:05.280 Where does a affect? 395 00:21:05.280 --> 00:21:08.039 It is added to the current velocity 396 00:21:08.039 --> 00:21:10.679 so v0 is also the current velocity 397 00:21:10.679 --> 00:21:15.323 v0 affects the current velocity, creating a new velocity 398 00:21:17.679 --> 00:21:19.440 A new velocity is created 399 00:21:19.440 --> 00:21:21.799 and v has changed 400 00:21:21.799 --> 00:21:23.599 This part has been created 401 00:21:23.599 --> 00:21:26.730 So where does v affect? 402 00:21:26.730 --> 00:21:29.080 It adds to the current position 403 00:21:29.080 --> 00:21:31.559 and changes the future position 404 00:21:31.559 --> 00:21:35.885 So when you push from behind like this, force is generated 405 00:21:35.885 --> 00:21:39.119 Force means acceleration is created 406 00:21:39.119 --> 00:21:43.440 Then, by affecting this part, a new v is created 407 00:21:43.440 --> 00:21:47.320 Then, the structure that creates this structure 408 00:21:47.320 --> 00:21:49.119 where the player P0 moves to P 409 00:21:49.119 --> 00:21:53.310 can be seen as the formula for uniform motion 410 00:21:53.310 --> 00:21:57.359 Then, what are all the games 411 00:21:57.359 --> 00:21:59.400 or realistic content 412 00:21:59.400 --> 00:22:01.960 that we create? 413 00:22:01.960 --> 00:22:04.119 They happen in virtual space 414 00:22:04.119 --> 00:22:06.559 We simulate in virtual space 415 00:22:06.559 --> 00:22:08.919 To do that 416 00:22:08.919 --> 00:22:13.239 we have no choice but to understand the dynamics part of kinematics 417 00:22:13.239 --> 00:22:15.487 Games are ultimately about creating dynamics 418 00:22:15.487 --> 00:22:18.840 that are identical to reality, similar to it 419 00:22:18.840 --> 00:22:21.440 So we have to use this kinematics 420 00:22:21.440 --> 00:22:23.000 in our games 421 00:22:23.000 --> 00:22:24.960 The important thing here is 422 00:22:24.960 --> 00:22:27.960 the vector 423 00:22:27.960 --> 00:22:31.050 Then, if we look at the content a little more 424 00:22:34.030 --> 00:22:36.719 P0 that you see here 425 00:22:36.719 --> 00:22:40.191 is just the simple position of a certain player 426 00:22:40.191 --> 00:22:43.039 Position 427 00:22:43.039 --> 00:22:44.679 P is also just a position 428 00:22:44.679 --> 00:22:48.119 Here, t is a scalar value, time 429 00:22:48.119 --> 00:22:51.680 Here, v means this arrow 430 00:22:51.680 --> 00:22:54.359 So we draw a vector 431 00:22:54.359 --> 00:22:58.960 on the head like this, an arrow like this 432 00:22:58.960 --> 00:23:00.039 What is this? 433 00:23:00.039 --> 00:23:02.080 It's an arrow, a symbol for a vector 434 00:23:02.080 --> 00:23:05.640 a is also acceleration, gravitational acceleration 435 00:23:05.640 --> 00:23:07.200 The arrow is acting downward 436 00:23:07.200 --> 00:23:09.880 So, this is also an arrow 437 00:23:09.880 --> 00:23:12.880 F is also an arrow, a is also an arrow 438 00:23:12.880 --> 00:23:14.760 The m here is mass, so it's just the number 1 439 00:23:14.760 --> 00:23:16.359 A scalar value 440 00:23:16.359 --> 00:23:18.200 We can express it like this 441 00:23:18.200 --> 00:23:20.679 This is the formula for uniform motion 442 00:23:20.679 --> 00:23:23.829 We'll use this to create 443 00:23:23.829 --> 00:23:26.919 our player's movement 444 00:23:26.919 --> 00:23:28.760 Let's use this 445 00:23:28.760 --> 00:23:33.280 to create our player's movement 446 00:23:33.280 --> 00:23:34.680 If you look at the code 447 00:23:34.680 --> 00:23:37.520 this part itself 448 00:23:37.520 --> 00:23:40.959 this much in this part 449 00:23:40.959 --> 00:23:44.079 is v 450 00:23:44.079 --> 00:23:46.280 Why? What is P? 451 00:23:46.280 --> 00:23:49.040 P0 + vt 452 00:23:49.040 --> 00:23:51.440 This is a vector 453 00:23:51.440 --> 00:23:57.119 and v is a vector with magnitude and direction 454 00:23:57.119 --> 00:24:01.560 So V is created by multiplying direction × magnitude 455 00:24:01.560 --> 00:24:05.959 The t behind here is called deltaTime 456 00:24:05.959 --> 00:24:07.959 This transform.Translate 457 00:24:07.959 --> 00:24:11.959 This internally implements this formula 458 00:24:11.959 --> 00:24:15.927 which is the internal function of this translate 459 00:24:18.719 --> 00:24:21.319 So this deltaTime behind here 460 00:24:21.319 --> 00:24:23.359 means t 461 00:24:23.359 --> 00:24:26.880 So, let's take a quick look at 462 00:24:26.880 --> 00:24:28.421 what this deltaTime is 463 00:24:31.599 --> 00:24:35.119 Let's take a closer look at deltaTime 464 00:24:35.119 --> 00:24:37.880 If you look at the one in front 465 00:24:37.880 --> 00:24:39.959 and below 466 00:24:39.959 --> 00:24:43.079 this is a new PC 467 00:24:43.079 --> 00:24:44.920 I opened up a new computer and bought it 468 00:24:44.920 --> 00:24:47.160 I bought it with the latest graphics specifications 469 00:24:47.160 --> 00:24:49.119 memory, hard disk 470 00:24:49.119 --> 00:24:51.359 and everything 471 00:24:51.359 --> 00:24:53.119 The one below is 472 00:24:53.119 --> 00:24:56.680 a PC that's about 5 years old 473 00:24:56.680 --> 00:24:59.119 It wasn't bad then 474 00:24:59.119 --> 00:25:03.479 but it became very slow after about 5 years 475 00:25:03.479 --> 00:25:06.880 You see this dotted line on the graph above 476 00:25:06.880 --> 00:25:08.719 This graph shows 477 00:25:08.719 --> 00:25:12.839 how often a new PC can perform operations 478 00:25:12.839 --> 00:25:13.880 in 1 second 479 00:25:13.880 --> 00:25:18.680 So let's say this is 1 second 480 00:25:18.680 --> 00:25:22.160 How can a new PC perform in 1 second? 481 00:25:22.160 --> 00:25:24.160 When this object moves 482 00:25:24.160 --> 00:25:28.239 it can move one, two, three, or four times in total 483 00:25:28.239 --> 00:25:30.928 It can perform four spaces in 1 second 484 00:25:30.928 --> 00:25:34.599 And two times under 485 00:25:34.599 --> 00:25:35.319 Do you understand? 486 00:25:35.319 --> 00:25:37.479 You can do this two times 487 00:25:37.479 --> 00:25:41.160 and let's say this character can move 488 00:25:41.160 --> 00:25:44.119 1 meter each time it moves 489 00:25:44.119 --> 00:25:46.886 Then the new PC above 490 00:25:46.886 --> 00:25:48.319 moves four times 491 00:25:48.319 --> 00:25:50.160 so it moves 1m each time 492 00:25:50.160 --> 00:25:54.719 So how many meters can it move in 1 second 493 00:25:54.719 --> 00:25:56.599 on the first new PC? 494 00:25:56.599 --> 00:25:59.040 4 meters, right? 495 00:25:59.040 --> 00:26:02.040 Then, the 5-year-old PC below 496 00:26:02.040 --> 00:26:03.280 can move twice 497 00:26:03.280 --> 00:26:05.040 Likewise, it can move 1 meter 498 00:26:05.040 --> 00:26:07.439 each time it moves 499 00:26:07.439 --> 00:26:12.479 Then it will move 2 meters in 1 second 500 00:26:12.479 --> 00:26:15.680 How about this? 501 00:26:15.680 --> 00:26:18.640 Since it's a new PC, it can move 4 meters in 1 second 502 00:26:18.640 --> 00:26:20.839 and this one can move 2 meters 503 00:26:20.839 --> 00:26:22.880 The PC above it can move fast 504 00:26:22.880 --> 00:26:25.959 when you play 505 00:26:25.959 --> 00:26:27.119 the game 506 00:26:27.119 --> 00:26:29.880 In other words, if a 5-year-old PC and a new PC play a game 507 00:26:29.880 --> 00:26:33.479 the first new PC will always win 508 00:26:33.479 --> 00:26:35.359 This is so unfair that 509 00:26:35.359 --> 00:26:38.119 users will stop playing the game 510 00:26:38.119 --> 00:26:42.770 Do you hear the sound of the low-priced users leaving? 511 00:26:42.770 --> 00:26:45.520 This is so unfair that 512 00:26:45.520 --> 00:26:47.880 the rules are so unfair 513 00:26:47.880 --> 00:26:50.560 So how can we make them arrive 514 00:26:50.560 --> 00:26:53.880 at the same location 1 second later? 515 00:26:53.880 --> 00:26:56.400 This is a very important point 516 00:26:56.400 --> 00:26:58.280 Then, instead of 4m or 2m 517 00:26:58.280 --> 00:27:02.640 how can we make them move at the same speed 1 second later 518 00:27:02.640 --> 00:27:04.880 and arrive at the same final destination? 519 00:27:04.880 --> 00:27:07.731 This is the core of deltaTime 520 00:27:09.810 --> 00:27:11.839 There is something called Delta in front of this 521 00:27:11.839 --> 00:27:15.160 This Delta is displacement and change 522 00:27:15.160 --> 00:27:16.920 This is displacement time 523 00:27:16.920 --> 00:27:19.079 What has changed? Time has changed 524 00:27:19.079 --> 00:27:20.199 How has it changed? 525 00:27:20.199 --> 00:27:24.119 Right here 526 00:27:24.119 --> 00:27:25.920 how long did it take from the first 527 00:27:25.920 --> 00:27:29.079 to the end of this frame? 528 00:27:29.079 --> 00:27:32.359 This is deltaTime 529 00:27:32.359 --> 00:27:35.079 If the whole thing is 1 second 530 00:27:35.079 --> 00:27:36.520 when you do it 4 times 531 00:27:36.520 --> 00:27:38.920 each frame, each space 532 00:27:38.920 --> 00:27:41.959 we call it a frame 533 00:27:41.959 --> 00:27:44.880 Did you play this game when you were young? 534 00:27:44.880 --> 00:27:47.280 There's a book like this 535 00:27:47.280 --> 00:27:50.683 If you have a book, you draw a picture here 536 00:27:50.683 --> 00:27:53.239 How about on the back? 537 00:27:53.239 --> 00:27:55.959 You draw a picture like this on the back 538 00:27:55.959 --> 00:27:57.880 A running picture 539 00:27:57.880 --> 00:28:00.239 and then we'll draw this on every page of the book 540 00:28:00.239 --> 00:28:04.319 and quickly flip through the book 541 00:28:04.319 --> 00:28:06.079 What if we flip through it quickly? 542 00:28:06.079 --> 00:28:09.280 We can create an animation 543 00:28:09.280 --> 00:28:10.119 that looks like it's running 544 00:28:10.119 --> 00:28:12.439 You've probably played this game before 545 00:28:12.439 --> 00:28:14.880 There's each of these 546 00:28:14.880 --> 00:28:16.640 What do we call each of these? 547 00:28:16.640 --> 00:28:18.560 It's a frame 548 00:28:18.560 --> 00:28:22.119 In some places, it's called a tick 549 00:28:22.119 --> 00:28:25.839 In Unity, each of these is called a frame 550 00:28:25.839 --> 00:28:29.439 Usually, in the animation or film industry 551 00:28:29.439 --> 00:28:31.719 for us to see these smoothly 552 00:28:31.719 --> 00:28:35.439 how many frames are created per second? 553 00:28:35.439 --> 00:28:37.439 These ones 554 00:28:37.439 --> 00:28:40.704 These are produced at about 24 frames per second 555 00:28:40.704 --> 00:28:43.839 That's why we call this frame rate per second 556 00:28:43.839 --> 00:28:47.941 or frames per second, fps 557 00:28:50.119 --> 00:28:52.445 This is not first-person shooting 558 00:28:52.445 --> 00:28:53.959 That's right, frame per second means 559 00:28:53.959 --> 00:28:57.199 24 frames are created per second 560 00:28:57.199 --> 00:29:00.119 These are usually in the animation field 561 00:29:00.119 --> 00:29:03.920 When you watch a movie in the theater, animated movies 562 00:29:03.920 --> 00:29:06.920 usually use about 24 frames 563 00:29:06.920 --> 00:29:08.220 Then, games 564 00:29:08.220 --> 00:29:12.520 usually use about 30 to 60 frames 565 00:29:12.520 --> 00:29:15.470 Content such as VR 566 00:29:15.470 --> 00:29:17.959 is available in at least 60 frames on mobile 567 00:29:17.959 --> 00:29:22.040 PCs use 90 frames or more 568 00:29:22.040 --> 00:29:25.000 Why? So that users don't feel dizzy 569 00:29:25.000 --> 00:29:27.119 when they turn their heads or eyes 570 00:29:27.119 --> 00:29:28.719 This frame rate per second 571 00:29:28.719 --> 00:29:32.119 fps is used 572 00:29:32.119 --> 00:29:37.359 Now, this deltaTime plays a very important role 573 00:29:37.359 --> 00:29:39.959 How short it takes 574 00:29:39.959 --> 00:29:44.512 will help determine the frame rate per second 575 00:29:44.512 --> 00:29:48.400 So, here's how deltaTime is used 576 00:29:48.400 --> 00:29:51.079 in the uniform motion formula 577 00:29:51.079 --> 00:29:54.520 If you look, this can move 1m 578 00:29:54.520 --> 00:30:00.881 However, the time taken for each section is 0.25 seconds 579 00:30:00.881 --> 00:30:04.131 so if you divide it by 1/4, it becomes 0.25 seconds 580 00:30:04.131 --> 00:30:08.750 So when we move, the distance 581 00:30:08.750 --> 00:30:12.100 is space S, just let's call it S 582 00:30:12.100 --> 00:30:16.059 Then, in terms of distance and time, let's call it deltaTime 583 00:30:16.059 --> 00:30:18.043 × D 584 00:30:20.679 --> 00:30:26.720 That's when we get this final location 585 00:30:26.720 --> 00:30:32.875 So, we have S × distance × time 586 00:30:32.875 --> 00:30:36.399 Let's see, when we do distance × time t, these two things? 587 00:30:36.399 --> 00:30:37.849 It moves 1m 588 00:30:37.849 --> 00:30:40.899 Let's multiply time by deltaTime 589 00:30:40.899 --> 00:30:43.959 What do we get? 0.25 seconds 590 00:30:43.959 --> 00:30:45.859 What is the value? 591 00:30:45.859 --> 00:30:50.009 The final distance traveled is 0.25 meters 592 00:30:50.009 --> 00:30:52.639 So, how many meters did it move when moving this section? 593 00:30:52.639 --> 00:30:54.239 0.25 meters 594 00:30:54.239 --> 00:30:57.839 After this, 0.25 m, 0.25 m, 0.25 m 595 00:30:57.839 --> 00:31:03.159 If we add them all up, the final distance it moved is 1 meter 596 00:31:03.159 --> 00:31:06.109 The same goes for the bottom, even though it's slow fit 597 00:31:06.109 --> 00:31:10.239 But it takes 0.5 seconds per section in deltaTime 598 00:31:10.239 --> 00:31:12.889 In this case, it took 0.5 seconds to move 1 meter 599 00:31:12.889 --> 00:31:17.760 If we multiply the two, how many meters did it move when moving this section? 600 00:31:17.760 --> 00:31:21.160 0.5 meters 601 00:31:21.160 --> 00:31:24.839 If we add the two, how many meters did it move? 1 meter 602 00:31:24.839 --> 00:31:28.289 So before, this one was 4 meters, and this one was 2 meters 603 00:31:28.289 --> 00:31:30.439 but now the two are the same 604 00:31:30.439 --> 00:31:34.320 So, deltaTime is used like this 605 00:31:34.320 --> 00:31:36.520 So, in the uniform motion formula 606 00:31:36.520 --> 00:31:40.640 P = P0 + vt 607 00:31:40.640 --> 00:31:44.234 but P = P0 + vt, the t at the end 608 00:31:44.234 --> 00:31:47.200 is the time of the movement 609 00:31:47.200 --> 00:31:51.307 Because of that time, we multiplied by deltaTime in the code 610 00:31:51.307 --> 00:31:54.320 but for synchronization processing 611 00:31:54.320 --> 00:31:57.920 you must multiply deltaTime 612 00:31:57.920 --> 00:32:01.239 This isn't just used for simple movement, right? 613 00:32:01.239 --> 00:32:04.839 Let's take a look at the form that you rotated 614 00:32:04.839 --> 00:32:06.289 Here's one character 615 00:32:06.289 --> 00:32:08.559 and here's two of them 616 00:32:08.559 --> 00:32:12.434 They're both looking this way 617 00:32:12.434 --> 00:32:14.760 Let's say there's a hammer here 618 00:32:14.760 --> 00:32:20.373 There's a hammer like this 619 00:32:20.373 --> 00:32:24.423 When they both say Start!, they'll spin around 620 00:32:24.423 --> 00:32:27.760 They'll spin around and hit this guy with the hammer 621 00:32:27.760 --> 00:32:31.260 This is the new PC, this is the old PC 622 00:32:31.260 --> 00:32:33.040 This guy can spin faster, right? 623 00:32:33.040 --> 00:32:37.190 Boom! What if he spins around, catches the hammer, and hits him? 624 00:32:37.190 --> 00:32:39.559 The new PC will win, right? 625 00:32:39.559 --> 00:32:41.859 That's why you have to multiply by 626 00:32:41.859 --> 00:32:45.359 deltaTime when processing the spin 627 00:32:45.359 --> 00:32:48.018 Okay, let's look at this case this time 628 00:32:50.640 --> 00:32:53.490 I'll put a pill here like this 629 00:32:53.490 --> 00:32:55.475 I'll put it like this 630 00:32:57.666 --> 00:33:05.003 When you say Start!, you can each take this pill 631 00:33:05.003 --> 00:33:07.716 you can each take it when you say Start! 632 00:33:07.716 --> 00:33:11.559 When you say Start!, this guy can take it, and this guy can take it 633 00:33:11.559 --> 00:33:15.600 At that time, this guy is the pill that expands 634 00:33:15.600 --> 00:33:19.920 This is the new PC, and this is the old PC 635 00:33:19.920 --> 00:33:22.570 This one will eat this and zoom in, how about that? 636 00:33:22.570 --> 00:33:24.187 It zooms in fast, right? 637 00:33:24.187 --> 00:33:27.037 4 times per second, and this one can zoom in twice 638 00:33:27.037 --> 00:33:28.559 so this one will zoom in four times 639 00:33:28.559 --> 00:33:30.709 So what does this one do? Boom 640 00:33:30.709 --> 00:33:35.599 So after it gets this big, I stomp on it and bang! 641 00:33:35.599 --> 00:33:38.239 This one's definitely going to win the game 642 00:33:38.239 --> 00:33:41.289 That is, when you rotate, what do you have to multiply by? 643 00:33:41.289 --> 00:33:43.280 You have to multiply by deltaTime 644 00:33:43.280 --> 00:33:46.030 When you try to change 645 00:33:46.030 --> 00:33:49.080 the position, rotation, and scale 646 00:33:49.080 --> 00:33:52.630 used in this transform component 647 00:33:52.630 --> 00:33:56.230 you have to multiply by deltaTime 648 00:33:56.230 --> 00:33:58.065 to synchronize them 649 00:34:01.842 --> 00:34:06.640 That's how we found out about deltaTime 650 00:34:06.640 --> 00:34:11.015 Next, let's change 651 00:34:11.015 --> 00:34:12.919 this transform.Translate 652 00:34:12.919 --> 00:34:15.019 to the uniform motion formula 653 00:34:15.019 --> 00:34:17.039 we just learned 654 00:34:17.039 --> 00:34:19.689 Instead of using the one provided by Unity 655 00:34:19.689 --> 00:34:22.689 let's implement dynamics by directly working on physics 656 00:34:22.689 --> 00:34:25.039 using the uniform motion formula 657 00:34:25.039 --> 00:34:26.205 What is the movement formula? 658 00:34:26.205 --> 00:34:30.960 It's P = P0 + vt 659 00:34:30.960 --> 00:34:33.460 So what we need first is P0 660 00:34:33.460 --> 00:34:36.522 P0 will be the current position of the player 661 00:34:40.287 --> 00:34:42.821 So, let's create P0 first 662 00:34:42.821 --> 00:34:47.871 Vector3, this is the data type in front 663 00:34:47.871 --> 00:34:50.471 It allows you to use the three elements 664 00:34:50.471 --> 00:34:53.512 provided by Unity: x, y, and z 665 00:34:53.512 --> 00:34:55.185 That's why it has the 3 at the end 666 00:34:55.187 --> 00:34:58.850 In 2D, it's Vector2 667 00:34:58.850 --> 00:35:01.750 When there's only one number? Just use float 668 00:35:01.750 --> 00:35:05.360 Since we're in 3D, let's put it like this: Vector3 669 00:35:05.360 --> 00:35:08.195 Let's put it as P0 670 00:35:08.195 --> 00:35:10.645 This is the current position of the player 671 00:35:10.645 --> 00:35:13.745 so there's a game object 672 00:35:13.745 --> 00:35:15.000 that PlayerMove is using 673 00:35:15.000 --> 00:35:18.000 Who has this player's position? 674 00:35:18.000 --> 00:35:19.116 Transform has it 675 00:35:19.116 --> 00:35:21.569 If we get this position value 676 00:35:21.569 --> 00:35:24.360 we can get its current position value 677 00:35:24.360 --> 00:35:26.236 How do we use it? Here's how you can write it 678 00:35:26.236 --> 00:35:28.686 transform.position 679 00:35:28.686 --> 00:35:33.279 If you write it like this, P0 is created right away 680 00:35:33.279 --> 00:35:37.779 This is putting my current position into P0 681 00:35:37.779 --> 00:35:40.729 Next, we need vt, right? 682 00:35:40.729 --> 00:35:45.383 So if we do vt to Vector3 683 00:35:45.383 --> 00:35:51.906 what happens to v? This much will be v 684 00:35:51.906 --> 00:35:53.424 This much is v 685 00:35:55.639 --> 00:35:58.489 The thing after this is direction, and this is magnitude 686 00:35:58.489 --> 00:36:01.739 so this much in magnitude × direction is v 687 00:36:01.739 --> 00:36:03.919 Next, t is deltaTime 688 00:36:03.919 --> 00:36:10.279 So if we multiply this by the end, this becomes vt 689 00:36:10.279 --> 00:36:14.026 Then, let's create the last P = P0 + vt 690 00:36:14.026 --> 00:36:20.000 P = P0 + vt 691 00:36:20.000 --> 00:36:22.900 It will be like this, then it will finally be created according to this formula 692 00:36:22.900 --> 00:36:25.700 Since we got the value like this 693 00:36:25.700 --> 00:36:28.919 it should be updated to my final current position 694 00:36:28.919 --> 00:36:32.269 So transform.position 695 00:36:32.269 --> 00:36:33.419 What do I put 696 00:36:33.419 --> 00:36:35.619 in my current position? If I put P 697 00:36:35.619 --> 00:36:37.760 ​​this value will be updated 698 00:36:37.760 --> 00:36:42.720 This part is no longer needed so that you can delete it 699 00:36:42.720 --> 00:36:48.670 We create this using the uniform motion formula 700 00:36:48.670 --> 00:36:51.599 that changes the current player's position 701 00:36:51.599 --> 00:36:53.787 Let's see if it has changed the same 702 00:36:56.228 --> 00:37:00.117 If you press the play button, the user will continue to move to the right 703 00:37:02.000 --> 00:37:03.064 It looks like this 704 00:37:03.064 --> 00:37:06.811 Implementing Movement Based on User Input 705 00:37:07.336 --> 00:37:10.436 Then, this time, let's implement movement 706 00:37:10.436 --> 00:37:11.687 based on user input 707 00:37:14.857 --> 00:37:18.357 User input creates this that can get 708 00:37:18.357 --> 00:37:21.775 the direction based on the user's input 709 00:37:21.775 --> 00:37:23.625 It allows you to get the user's direction 710 00:37:23.625 --> 00:37:25.325 What is the direction here? 711 00:37:25.325 --> 00:37:28.160 This part will be the user's direction 712 00:37:28.160 --> 00:37:29.810 In particular, since this is the size 713 00:37:29.810 --> 00:37:32.759 this part can be limited to the direction 714 00:37:32.759 --> 00:37:35.736 Here, the parts that we need to learn a little more about 715 00:37:38.119 --> 00:37:39.969 Vector3.right are 716 00:37:39.969 --> 00:37:42.319 that this Vector3 part 717 00:37:42.319 --> 00:37:46.769 creates a direction 718 00:37:46.769 --> 00:37:49.440 with three components: x, y, and z 719 00:37:49.440 --> 00:37:53.383 In Unity, x means right 720 00:37:53.383 --> 00:38:00.000 y means up, and z means directly in front 721 00:38:00.000 --> 00:38:01.313 In English 722 00:38:03.559 --> 00:38:07.009 this x direction can be called right 723 00:38:07.009 --> 00:38:08.737 this can be called up 724 00:38:08.737 --> 00:38:10.156 and this can be called forward 725 00:38:11.720 --> 00:38:15.180 When it becomes like this 726 00:38:16.647 --> 00:38:20.597 How does each value go into x, y, and z? 727 00:38:20.597 --> 00:38:23.279 Vector3.right needs to enter the values ​​of these three components 728 00:38:23.279 --> 00:38:27.179 In other words, since x is right, the value goes into this as 1 729 00:38:27.179 --> 00:38:30.360 y goes into 0, and z also goes into 0 730 00:38:30.360 --> 00:38:34.110 Since it will go to the right if there is no value 731 00:38:34.110 --> 00:38:35.800 Its size is 1 732 00:38:35.800 --> 00:38:37.900 Here's how to find the magnitude 733 00:38:37.900 --> 00:38:44.039 You can find it like this, √(x^2 + y^2 + z^2) 734 00:38:44.039 --> 00:38:47.379 Since this is 1, the remainder is 0, and the square root of 1 is 1 735 00:38:47.379 --> 00:38:49.594 So, the magnitude becomes 1 736 00:38:52.479 --> 00:38:54.629 It becomes like this 737 00:38:54.629 --> 00:38:58.240 Then, in addition to the right, there will also be up 738 00:38:58.240 --> 00:39:00.190 What will up be like? 739 00:39:00.190 --> 00:39:03.921 In this form, you only need to enter a value for the y-axis 740 00:39:03.921 --> 00:39:07.821 That is, x is 0, and y is 1 741 00:39:07.821 --> 00:39:09.471 When is it going forward? 742 00:39:09.471 --> 00:39:13.160 It'll be 0 for y and 1 for z 743 00:39:13.160 --> 00:39:16.399 What do you multiply when the direction changes? 744 00:39:16.399 --> 00:39:21.519 I said that if you multiply by -1, the vector will flip 745 00:39:21.519 --> 00:39:25.019 So if you say you're going backward 746 00:39:25.019 --> 00:39:27.720 If you want to go backwards in a vector, this is in front 747 00:39:27.720 --> 00:39:30.440 You can multiply by -1 748 00:39:30.440 --> 00:39:34.690 On the left, multiply x by -1 749 00:39:34.690 --> 00:39:37.239 That means multiply by × -1 750 00:39:37.239 --> 00:39:41.039 Since each component is multiplied like this 751 00:39:41.039 --> 00:39:44.000 0 × -1 is 0 752 00:39:44.000 --> 00:39:50.440 So, you can also do this to go down 753 00:39:50.440 --> 00:39:53.290 So, if you × -1, the vector is flipped 754 00:39:53.290 --> 00:39:54.910 You just need to know this 755 00:39:56.920 --> 00:39:59.220 Then, let's implement the content 756 00:39:59.220 --> 00:40:02.170 that receives user input and makes the player 757 00:40:02.170 --> 00:40:04.040 move up, down, left, and right 758 00:40:04.040 --> 00:40:08.090 Then, let's first get the user's input 759 00:40:08.090 --> 00:40:10.467 to create a direction here 760 00:40:15.299 --> 00:40:22.094 We want to create a direction by getting the user's input 761 00:40:25.119 --> 00:40:27.119 Then, how do we get the user's input? 762 00:40:27.119 --> 00:40:31.239 We use a class called Input to get the user's input 763 00:40:31.239 --> 00:40:34.962 Then, picture class 1 in your head 764 00:40:34.962 --> 00:40:36.600 Then, what happens? 765 00:40:36.600 --> 00:40:38.700 We go into the function as an attribute 766 00:40:38.700 --> 00:40:41.150 We'll go into the function here 767 00:40:41.150 --> 00:40:44.640 We'll go into the GetAxis function 768 00:40:44.640 --> 00:40:46.640 GetAxis can get the inputs 769 00:40:46.640 --> 00:40:49.079 that the user is continuously pressing 770 00:40:49.079 --> 00:40:51.579 Here, we'll get the Horizontal input 771 00:40:51.579 --> 00:40:56.304 which is the left and right input 772 00:40:57.880 --> 00:41:01.912 If the user doesn't press any key 773 00:41:01.912 --> 00:41:04.760 GetAxis returns a value of 0 774 00:41:04.760 --> 00:41:10.410 However, if the user presses the A key or the left arrow key 775 00:41:10.410 --> 00:41:13.079 it returns a value of -1 776 00:41:13.079 --> 00:41:18.429 It gradually changes from 0 to -0.1, -0.2 777 00:41:18.429 --> 00:41:21.479 and returns a value up to -1 778 00:41:21.479 --> 00:41:25.079 If the right key is pressed, it returns a value of +1 779 00:41:25.079 --> 00:41:26.129 We'll use this 780 00:41:26.129 --> 00:41:29.200 to create the direction of this vector 781 00:41:29.200 --> 00:41:33.750 We'll store this as a value for the Horizontal input 782 00:41:33.750 --> 00:41:38.054 for the left and right input, which is a container called float h 783 00:41:38.054 --> 00:41:40.679 So, where is this Horizontal value? 784 00:41:40.679 --> 00:41:47.129 If you go to Unity and scroll down to the Edit menu 785 00:41:47.129 --> 00:41:49.961 you will find Project Settings 786 00:41:49.961 --> 00:41:54.959 If you go in there, you'll see Input Manager 787 00:41:54.959 --> 00:41:57.566 There's a section called Axes in the Input Manager 788 00:41:57.566 --> 00:42:01.665 If you open that, you'll see Horizontal 789 00:42:01.665 --> 00:42:03.715 If you look under that, you'll see Vertical, Fire1 790 00:42:03.715 --> 00:42:08.959 that Unity has mapped 791 00:42:08.959 --> 00:42:10.839 inputs to in advance 792 00:42:10.839 --> 00:42:13.920 If you open Horizontal, the name is Horizontal 793 00:42:13.920 --> 00:42:19.799 and here it says Negative Button, left 794 00:42:19.799 --> 00:42:23.040 Next, Positive Button is right 795 00:42:23.040 --> 00:42:26.279 That means the left and right arrow keys 796 00:42:26.279 --> 00:42:28.239 It means negative and positive numbers 797 00:42:28.239 --> 00:42:33.289 the Alt key and other alternative Negative buttons 798 00:42:33.289 --> 00:42:34.720 are the a and d keys 799 00:42:34.720 --> 00:42:38.170 So when you press the left, right, a, and d keys 800 00:42:38.170 --> 00:42:40.480 Horizontal responds 801 00:42:40.480 --> 00:42:44.679 This value passes a value between -1 and 1 802 00:42:44.679 --> 00:42:46.322 It's defined here 803 00:42:46.322 --> 00:42:48.440 It's defined like this 804 00:42:48.440 --> 00:42:51.090 Vertical is up, down 805 00:42:51.090 --> 00:42:53.119 and s, w 806 00:42:53.119 --> 00:42:55.160 What's in fire1? 807 00:42:55.160 --> 00:42:58.310 Left ctrl key or left mouse button 808 00:42:58.310 --> 00:43:00.239 0 is the left mouse button 809 00:43:00.239 --> 00:43:03.239 The values ​​are defined like this 810 00:43:03.239 --> 00:43:05.589 We put the values ​​defined here 811 00:43:05.589 --> 00:43:07.572 and work with them 812 00:43:07.572 --> 00:43:13.279 We will process the values ​​using these values 813 00:43:13.279 --> 00:43:15.799 Then, let's first change 814 00:43:15.799 --> 00:43:20.000 the direction to the value we put here instead of this 815 00:43:20.000 --> 00:43:26.640 So we're going to put dir in Vector3 816 00:43:26.640 --> 00:43:31.119 This is right 817 00:43:31.119 --> 00:43:32.520 It's the right value 818 00:43:32.520 --> 00:43:37.343 If we do this, this dir has right in it 819 00:43:37.343 --> 00:43:40.799 and if we just do this instead of right, what happens? 820 00:43:40.799 --> 00:43:43.919 It moves to the right, and the same value will appear 821 00:43:43.919 --> 00:43:46.919 At that time, if we want to 822 00:43:46.919 --> 00:43:49.440 apply the user's input value to this 823 00:43:49.440 --> 00:43:54.039 we multiply it by the scalar value h 824 00:43:54.039 --> 00:43:56.479 Then what happens internally? 825 00:43:56.479 --> 00:44:00.719 Right is 1, 0, 0 826 00:44:00.719 --> 00:44:03.280 and if h is -1 here 827 00:44:03.280 --> 00:44:05.599 if we press the left key and do this 828 00:44:05.599 --> 00:44:08.119 each component will be multiplied like this 829 00:44:08.119 --> 00:44:09.559 Then what happens? 830 00:44:09.559 --> 00:44:12.200 It will be -1, 0, 0, so it will be the left 831 00:44:12.200 --> 00:44:15.760 If we press the right, it will be +1, so it will just be 1, 0, 0 832 00:44:15.760 --> 00:44:17.080 and it will go to the right 833 00:44:17.080 --> 00:44:19.760 If we don't press anything, this has a value of 0 834 00:44:19.760 --> 00:44:23.919 So the direction will be 0, so nothing will move 835 00:44:23.919 --> 00:44:27.320 0 × 5 is all 0, right? 836 00:44:27.320 --> 00:44:30.520 So, if we multiply this by h here 837 00:44:30.520 --> 00:44:33.080 we can immediately set the direction 838 00:44:33.080 --> 00:44:36.280 Let's play this 839 00:44:36.280 --> 00:44:39.280 Play 840 00:44:39.280 --> 00:44:41.640 Let's press the left and right keys on the keyboard 841 00:44:41.640 --> 00:44:44.340 Then you can see that the character, the player 842 00:44:44.340 --> 00:44:47.320 moves left and right like this 843 00:44:47.320 --> 00:44:50.960 Okay? Then how about the up and down input? 844 00:44:50.960 --> 00:44:54.080 As I mentioned earlier 845 00:44:54.080 --> 00:44:56.919 what was this value in the Input Manager? 846 00:44:56.919 --> 00:44:59.719 It was Vertical Let's create another one 847 00:44:59.719 --> 00:45:04.320 Let's call it v, and this time, put it as Vertical 848 00:45:04.320 --> 00:45:07.559 You have to distinguish between upper and lower case letters 849 00:45:07.559 --> 00:45:10.719 Then the user's input is like this 850 00:45:10.719 --> 00:45:12.919 If I want to add one more Vertical 851 00:45:12.919 --> 00:45:15.599 do I have to create another direction to move it? 852 00:45:15.599 --> 00:45:16.719 You don't have to do that 853 00:45:16.719 --> 00:45:19.640 You can use vector addition 854 00:45:19.640 --> 00:45:23.590 How? What happens if you add 855 00:45:23.590 --> 00:45:27.440 these two vectors, one going to the right and one going up? 856 00:45:27.440 --> 00:45:30.039 I said you can put this here 857 00:45:30.039 --> 00:45:34.551 That's how this vector is created, right? 858 00:45:34.551 --> 00:45:37.440 So you can add the two vectors 859 00:45:37.440 --> 00:45:45.080 + Vector3.up * v, if you do this 860 00:45:45.080 --> 00:45:50.359 when the value is -1, it will go down, and the vector 861 00:45:50.359 --> 00:45:52.309 This is 0, 1, 0 862 00:45:52.309 --> 00:45:55.799 so when it's +1, it will just go up 863 00:45:55.799 --> 00:45:58.999 Then, if you change this formula 864 00:45:58.999 --> 00:46:00.599 for moving an object 865 00:46:00.599 --> 00:46:02.743 you can make it like this 866 00:46:11.280 --> 00:46:16.472 It's about finding directions 867 00:46:16.472 --> 00:46:17.919 Up to here, it's about finding directions 868 00:46:17.919 --> 00:46:20.892 What's the content below? 869 00:46:20.892 --> 00:46:22.242 It's about moving 870 00:46:22.242 --> 00:46:27.840 You can use sentences like this to distinguish them 871 00:46:27.840 --> 00:46:29.540 Then, moving 872 00:46:29.540 --> 00:46:32.159 always ends with the word moving 873 00:46:32.159 --> 00:46:34.609 If you want to change the direction or do various tasks 874 00:46:34.609 --> 00:46:37.159 you can just change the code here 875 00:46:37.159 --> 00:46:38.759 Even if you create a function 876 00:46:38.759 --> 00:46:44.080 you can just change and create this part of the function 877 00:46:44.080 --> 00:46:47.400 I've done it to move the user up, down, left, and right like this 878 00:46:47.400 --> 00:46:49.814 Let's test it, play 879 00:46:51.919 --> 00:46:56.869 Then, you can see that it moves when the user presses 880 00:46:56.869 --> 00:46:59.393 the left, right, up, down, left, and right keys 881 00:47:02.520 --> 00:47:05.320 Then, we'll continue to look at 882 00:47:05.320 --> 00:47:07.760 this part in more detail 883 00:47:07.760 --> 00:47:12.239 How can we see the light of a vector? 884 00:47:12.239 --> 00:47:15.789 You can see the light of a vector like this 885 00:47:15.789 --> 00:47:17.760 (1, 0, 0) 886 00:47:17.760 --> 00:47:20.746 What happens if you multiply it by h? 887 00:47:20.746 --> 00:47:23.880 (h, 0, 0) 888 00:47:23.880 --> 00:47:25.530 Let's add them 889 00:47:25.530 --> 00:47:27.880 The up × v of a vector can be seen like this 890 00:47:27.880 --> 00:47:31.359 (0, v, 0), let's add two of them 891 00:47:31.359 --> 00:47:36.000 Then, what will the final value be? (h, v, 0) 892 00:47:36.000 --> 00:47:39.900 In other words, can we put each component 893 00:47:39.900 --> 00:47:43.612 in x, y, and z like this? 894 00:47:43.612 --> 00:47:47.359 So we can modify our code like this 895 00:47:47.359 --> 00:47:48.687 If you place the part like this 896 00:47:50.960 --> 00:47:56.085 in the new Vector3 as (h, v, 0) 897 00:47:56.085 --> 00:48:00.960 the content will be the same 898 00:48:00.960 --> 00:48:04.035 Let's save and play again 899 00:48:06.599 --> 00:48:10.960 It can be implemented similarly when moving up, down, left, and right 900 00:48:10.960 --> 00:48:15.280 So, we add to the vector and extract the final result 901 00:48:15.280 --> 00:48:18.380 Those results can be entered into the vector like this 902 00:48:18.380 --> 00:48:20.320 and the content can be the same 903 00:48:20.320 --> 00:48:22.370 So, does that mean we don't need to add to the vector? 904 00:48:22.370 --> 00:48:24.080 You might say that 905 00:48:24.080 --> 00:48:26.346 No, adding to the vector is 906 00:48:26.346 --> 00:48:29.440 necessary because it implements the sum of all forces 907 00:48:29.440 --> 00:48:32.840 I'll show you that this can be used 908 00:48:32.840 --> 00:48:35.320 when you reduce the user's input to a single value 909 00:48:35.320 --> 00:48:37.320 The code may appear like this 910 00:48:37.320 --> 00:48:39.870 when you study and search 911 00:48:39.870 --> 00:48:43.239 on YouTube or Google 912 00:48:43.239 --> 00:48:47.289 Ultimately, these are based on adding to a vector 913 00:48:47.289 --> 00:48:49.792 I hope you understand this 914 00:48:51.049 --> 00:48:54.280 Let's summarize what we learned in this section 915 00:48:54.280 --> 00:48:57.239 First, we learned about vectors 916 00:48:57.239 --> 00:49:00.239 Vectors consist of magnitude and direction 917 00:49:00.239 --> 00:49:04.919 and can perform addition, subtraction, inner product, and outer product operations 918 00:49:04.919 --> 00:49:08.840 Second, we learned about the uniform motion formula 919 00:49:08.840 --> 00:49:11.190 We learned about the uniform motion formula for moving an object 920 00:49:11.190 --> 00:49:14.039 P = P0 + vt 921 00:49:14.039 --> 00:49:17.280 We created the player's movement 922 00:49:17.280 --> 00:49:20.919 We moved the player based on the uniform motion formula 923 00:49:20.919 --> 00:49:25.359 We also learned about the meaning and use of deltaTime 924 00:49:25.359 --> 00:49:29.080 We implemented movement according to user input 925 00:49:29.080 --> 00:49:32.116 We used the inf class to get the user's input 926 00:49:32.116 --> 00:49:35.216 and applied the player's movement by calculating the up, down, left, right directions 927 00:49:35.216 --> 00:49:37.137 based on the user's input 928 00:49:37.581 --> 00:49:41.031 Understanding Vectors Vector Vectors have magnitude and direction Can be added, subtracted, and multiplied (inner product, outer product) The sum of all forces can be expressed by adding vectors 929 00:49:41.031 --> 00:49:44.472 Direction=B-A (a formula to find the direction in which A wants to go to B) 930 00:49:44.472 --> 00:49:47.972 Understanding the Uniform Motion Formula and Creating Player Movement Uniform Motion Use the formulas for movement, velocity, and force as the physical laws for moving objects P=P0+vt / v=v0+at / F=ma 931 00:49:47.972 --> 00:49:51.481 DeltaTime The time between the previous frame and the current frame It is important to match the distance traveled per second regardless of the PC specifications 932 00:49:51.481 --> 00:49:52.723 Implementing movement based on user input User input processing Write code to respond to the input of the left and right keys, A, and D keys on the keyboard 933 00:49:52.723 --> 00:49:53.985 Write code to respond to the input of up, down, left, and right using Horizontal and Vertical registered in the properties of [Edit - Project Settings - Input Manager] 934 00:49:53.985 --> 00:49:55.188 Creating a direction Implementing the content of 'Creating a direction and moving according to user input' 935 00:49:55.188 --> 00:49:56.386 Using the value received from user input to create a direction (Vector3 dir=Vector3.right*h+Vector3.up*v) 936 00:49:56.386 --> 00:49:57.371 Using (h, 0, 0)+(0, v, 0)=(h, v, 0), change the script to new Vector3(h, v, 0)