WEBVTT 1 00:00:05.675 --> 00:00:09.825 Game Advanced Version Prototype version 1 2 00:00:27.475 --> 00:00:29.175 Hello everyone 3 00:00:29.175 --> 00:00:32.525 I'm Kim Hyunjin of FPS Game Development 4 00:00:33.025 --> 00:00:37.175 FPS is a genre that plays the shooting game 5 00:00:37.175 --> 00:00:40.475 from the perspective of a player character in a 3D space 6 00:00:40.975 --> 00:00:43.375 Through FPS game development 7 00:00:43.375 --> 00:00:47.475 We will actively utilize the 3D function 8 00:00:47.475 --> 00:00:51.475 Implementing position movement, directional rotation, jump etc 9 00:00:51.475 --> 00:00:53.575 In order to control character modeling 10 00:00:53.575 --> 00:00:58.025 We will also take a look at animation application method 11 00:00:58.775 --> 00:01:03.375 In this lesson, we will learn to calculate rotation value depending on the mouse movement 12 00:01:03.375 --> 00:01:06.925 and rotate the game object 13 00:01:06.925 --> 00:01:11.345 We will implement the function to follow around a particular object 14 00:01:11.345 --> 00:01:16.195 And take a look at the difference between world space and local space 15 00:01:16.195 --> 00:01:19.895 I will implement the movement of the character 16 00:01:19.895 --> 00:01:22.525 based on the direction that the camera is facing 17 00:01:22.525 --> 00:01:26.525 Project creation and setting, character rotation 18 00:01:27.325 --> 00:01:31.725 Let's try the project creation and setting 19 00:01:34.825 --> 00:01:37.025 Turn on the unity herb 20 00:01:38.325 --> 00:01:41.375 Click on the new project 21 00:01:42.975 --> 00:01:49.325 I will choose the template that says Universal 3D 22 00:01:50.675 --> 00:01:53.475 And download the template 23 00:01:55.825 --> 00:02:00.925 Until now, we used 3D Built-In Render Pipeline to 24 00:02:00.925 --> 00:02:03.425 create the project 25 00:02:03.425 --> 00:02:08.125 But we will use Universal 3D 26 00:02:10.075 --> 00:02:14.275 For the lecture in the second half, which is about shader graph 27 00:02:14.275 --> 00:02:16.825 We're creating the project with URP 28 00:02:17.825 --> 00:02:21.525 URP is a function to respond to multi-platform 29 00:02:21.525 --> 00:02:25.375 and expand the graphic function of unity 30 00:02:25.375 --> 00:02:29.075 It is one of the function called 31 00:02:29.075 --> 00:02:30.725 Scriptable Render Pipeline 32 00:02:32.225 --> 00:02:34.725 In this stage, the URP 33 00:02:34.725 --> 00:02:36.775 won't be explained in detail 34 00:02:37.675 --> 00:02:39.875 The detailed explanation will be 35 00:02:39.875 --> 00:02:43.425 done in the Shader lecture 36 00:02:45.025 --> 00:02:50.875 The project name will be called FPS 37 00:02:50.875 --> 00:02:54.175 Press the project creation button 38 00:02:56.475 --> 00:02:58.375 Let's try to develop it 39 00:02:58.375 --> 00:03:02.225 First, I will make a flat surface 40 00:03:03.575 --> 00:03:07.725 In the Hierarchy tab, press the (+) button and 3D object 41 00:03:07.725 --> 00:03:11.075 Next, choose Plane 42 00:03:11.775 --> 00:03:15.275 I will name this Ground 43 00:03:17.475 --> 00:03:22.675 Then, the scale value in the inspector 44 00:03:22.675 --> 00:03:28.575 X value which is 10, then modify the Z value to 10 45 00:03:28.575 --> 00:03:32.925 I have formed a wide surface 46 00:03:34.475 --> 00:03:39.325 I will try to color the surface 47 00:03:39.325 --> 00:03:42.775 I will make a folder in the project tab 48 00:03:42.775 --> 00:03:48.675 Press the (+) button and choose a folder from the top 49 00:03:50.225 --> 00:03:53.975 Let's name it Materials 50 00:03:56.825 --> 00:04:01.475 Double click the folder to go in 51 00:04:01.475 --> 00:04:06.325 Click on the (+) button and this time, material 52 00:04:06.325 --> 00:04:11.875 Choose the material menu in the middle and create it 53 00:04:11.875 --> 00:04:16.225 Let's name it MatGround 54 00:04:17.825 --> 00:04:20.525 Select the MatGround which is created 55 00:04:20.525 --> 00:04:23.475 Move to the inspector tab on the right 56 00:04:24.625 --> 00:04:26.125 In the Base Map 57 00:04:26.125 --> 00:04:29.675 Select a white color 58 00:04:29.675 --> 00:04:31.375 Based on your preference 59 00:04:31.375 --> 00:04:34.875 Choose a color that seems to be considered as the ground 60 00:04:34.875 --> 00:04:39.825 Let's make it a dark brown color 61 00:04:42.175 --> 00:04:46.075 When the setting is finished, from the hierarchy 62 00:04:46.075 --> 00:04:50.075 Choose a game object called Ground 63 00:04:50.075 --> 00:04:54.925 Mesh Renderer from the right inspector 64 00:04:54.925 --> 00:04:59.175 Expand the Materials menu inside 65 00:04:59.175 --> 00:05:03.025 And there is a material called Lit 66 00:05:03.025 --> 00:05:08.075 This will be replaced with the MatGround that we have developed 67 00:05:08.075 --> 00:05:13.075 Drag and drop 68 00:05:13.075 --> 00:05:18.525 You can see that it has turned into a brown color 69 00:05:18.525 --> 00:05:23.175 If you don't like the color, select MatGround again 70 00:05:23.175 --> 00:05:29.075 Choose the bar with the color on the Base Map 71 00:05:29.075 --> 00:05:30.875 and adjust it 72 00:05:32.275 --> 00:05:36.875 Next, Applying to the player that we are manipulating 73 00:05:36.875 --> 00:05:39.375 We will make a game object 74 00:05:41.375 --> 00:05:44.975 Press on the (+) button from the hierarchy tab 75 00:05:44.975 --> 00:05:51.075 This time, I will choose 3D Object - Capsule 76 00:05:51.775 --> 00:05:54.175 I will name this Player 77 00:05:55.025 --> 00:05:58.775 Next, the position value in the hierarchy transform will be 78 00:05:58.775 --> 00:06:07.125 set as 0,1,0 79 00:06:08.825 --> 00:06:10.925 In the middle of the screen like so 80 00:06:10.925 --> 00:06:14.725 You can see the capsule has appeared 81 00:06:16.125 --> 00:06:18.975 This is the basic setting 82 00:06:20.525 --> 00:06:23.925 Now, the character that has been developed 83 00:06:23.925 --> 00:06:27.125 I will rotate the Player 84 00:06:27.125 --> 00:06:32.775 I will rotate it based on the movement of the mouse 85 00:06:33.975 --> 00:06:39.425 Before rotating this player, the character 86 00:06:39.425 --> 00:06:43.075 I will rotate the camera first 87 00:06:44.325 --> 00:06:46.175 I will develop a script that 88 00:06:46.175 --> 00:06:48.525 plays the role of rotating it 89 00:06:49.825 --> 00:06:54.625 Select the Assets folder from the project tab 90 00:06:55.125 --> 00:07:00.725 Press the (+) button and select the folder 91 00:07:00.725 --> 00:07:03.625 Name it Scripts 92 00:07:04.975 --> 00:07:08.875 Double click on the Scripts folder 93 00:07:08.875 --> 00:07:11.375 And then press the (+) button again 94 00:07:11.375 --> 00:07:13.975 Choose C# Script 95 00:07:13.975 --> 00:07:17.575 I will name it CamRotate 96 00:07:19.475 --> 00:07:23.125 If it has been made, the CamRotate script 97 00:07:23.125 --> 00:07:27.875 will be dragged to the main camera and put together 98 00:07:27.875 --> 00:07:31.325 Drag and drop to the main camera 99 00:07:33.125 --> 00:07:35.775 When the main camera is selected 100 00:07:35.775 --> 00:07:39.725 CameRotate has to be added like so 101 00:07:41.175 --> 00:07:45.975 Double click and open up the script CamRotate 102 00:07:47.525 --> 00:07:49.675 In the script, first 103 00:07:49.675 --> 00:07:55.425 We will get input on the user's mouse 104 00:07:58.275 --> 00:08:07.575 Secondly, based on the input value that has been set 105 00:08:07.575 --> 00:08:13.675 We will decide the rotating direction 106 00:08:15.724 --> 00:08:25.974 And then, we will rotate the camera to the rotating direction 107 00:08:28.474 --> 00:08:31.724 In order to get the input of the user's mouse 108 00:08:31.724 --> 00:08:34.724 A class called Input is used 109 00:08:35.574 --> 00:08:42.174 Through a function called Input.GetAxis() 110 00:08:42.974 --> 00:08:45.774 Open brackets and as a string 111 00:08:45.774 --> 00:08:50.224 Mouse leave space X 112 00:08:50.224 --> 00:08:54.774 Depending on the left and right movement of the mouse 113 00:08:54.774 --> 00:08:59.124 The result of value changing could be achieved 114 00:09:00.524 --> 00:09:05.074 If you bring the mouse over on the function called GetAxis 115 00:09:05.074 --> 00:09:07.924 It says float at the very front 116 00:09:07.924 --> 00:09:11.524 When a code is implemented, this function 117 00:09:11.524 --> 00:09:17.424 ultimately returns a value called float 118 00:09:17.424 --> 00:09:21.574 Therefore, it puts the value at the front 119 00:09:21.574 --> 00:09:23.124 We need to get it 120 00:09:23.124 --> 00:09:25.574 In order to get the data 121 00:09:25.574 --> 00:09:27.924 We need something called a variable 122 00:09:27.924 --> 00:09:31.524 Because the data type is a float 123 00:09:31.524 --> 00:09:33.824 The variable to hold the data 124 00:09:33.824 --> 00:09:37.924 should obviously be made in the float data type 125 00:09:37.924 --> 00:09:43.324 Let's say float mouse_X 126 00:09:45.274 --> 00:09:51.124 When the mouse is moving left and right 127 00:09:51.124 --> 00:09:53.274 The Mouse X will receive a result 128 00:09:53.274 --> 00:09:55.774 Same for when the mouse is moving up and down 129 00:09:55.774 --> 00:09:59.074 There will be a function that operates in the same way 130 00:09:59.974 --> 00:10:05.824 So in the variable called float mouse_Y 131 00:10:05.824 --> 00:10:07.574 this value will be held 132 00:10:07.574 --> 00:10:16.624 Input.GetAxis and then Mouse Y 133 00:10:17.824 --> 00:10:22.124 Using the value of mouse_X and mouse_Y 134 00:10:22.124 --> 00:10:26.624 We will choose the rotation direction for the object 135 00:10:28.674 --> 00:10:32.574 First, the current angle value 136 00:10:34.124 --> 00:10:37.424 will be held in a local variable 137 00:10:38.174 --> 00:10:42.724 This variable called angle will be made to a Vector3 data type 138 00:10:42.724 --> 00:10:46.474 Over here, bring what is attached to the script 139 00:10:46.474 --> 00:10:49.574 Bring over the transform of the game object 140 00:10:49.574 --> 00:10:51.174 Hey, transform bring over 141 00:10:51.174 --> 00:10:54.074 the eulerAngles value that you have 142 00:10:54.074 --> 00:10:56.924 Get the current rotation value 143 00:10:58.024 --> 00:11:05.824 Then Hey, Angle, I'll modify your X value 144 00:11:05.824 --> 00:11:13.374 How much? As much as the modified value of mouse_Y 145 00:11:14.374 --> 00:11:18.074 The reason why we modify the x value of the angle 146 00:11:18.074 --> 00:11:22.324 mouse_Y instead of mouse_X 147 00:11:30.024 --> 00:11:33.724 There is a Hexagon object like so 148 00:11:35.524 --> 00:11:40.374 Let's say this is the X-axis 149 00:11:40.374 --> 00:11:42.974 And there is a Y-Axis facing upwards 150 00:11:43.874 --> 00:11:47.174 How would it turn out if 151 00:11:47.174 --> 00:11:48.974 we rotate the object around the center of this axis? 152 00:11:48.974 --> 00:11:53.724 It would rotate as if it is nodding its head 153 00:11:54.674 --> 00:11:57.724 When we are moving the mouse up and down 154 00:11:57.724 --> 00:12:01.274 we have to make it rotate like so 155 00:12:01.274 --> 00:12:06.124 Therefore the up and down movement of the mouse's value 156 00:12:06.124 --> 00:12:09.724 should be held in mouse_Y 157 00:12:09.724 --> 00:12:15.324 It is requesting for the object to rotate as much as mouse's y to the X-axis 158 00:12:15.324 --> 00:12:17.774 Then, what would happen if the mouse is moved up and down? 159 00:12:17.774 --> 00:12:23.074 The rotating value as if it is nodding will be set 160 00:12:24.374 --> 00:12:30.374 In reverse, what if the mouse is moved left and right? 161 00:12:30.374 --> 00:12:33.274 Instead of rotating as if nodding, how? 162 00:12:33.274 --> 00:12:36.874 Around the center of this green axis like so 163 00:12:36.874 --> 00:12:40.024 We should rotate it as if its shaking the head 164 00:12:41.574 --> 00:12:42.624 So what is this? 165 00:12:42.624 --> 00:12:46.374 The value should change based on the Y-axis 166 00:12:46.924 --> 00:12:50.424 So the current angle value of the X 167 00:12:50.424 --> 00:12:52.924 Rotate around the center of the X-axis 168 00:12:52.924 --> 00:12:59.564 += and multiply to mouse_Y 169 00:12:59.564 --> 00:13:02.814 We will multiply angular velocity 170 00:13:02.814 --> 00:13:10.614 200 multiplied by Time.deltaTime 171 00:13:10.614 --> 00:13:14.964 We have set it so that it would move in the same way in any situation 172 00:13:15.974 --> 00:13:18.074 Instead of writing down 200 right away 173 00:13:18.074 --> 00:13:21.174 Making a global variable will be 174 00:13:21.174 --> 00:13:22.774 more efficient 175 00:13:23.074 --> 00:13:30.624 So I will make an angular velocity through global variable 176 00:13:32.774 --> 00:13:37.874 It would be able to be modified anytime to public through the inspector 177 00:13:37.874 --> 00:13:42.174 This data type is will be called float rotSpeed 178 00:13:42.174 --> 00:13:44.224 The initial value will be set to 200 179 00:13:45.674 --> 00:13:50.224 So it could be replaced instead of this 200 180 00:13:50.224 --> 00:13:54.224 For this 200, let's modify this to rotSpeed 181 00:13:56.074 --> 00:13:58.524 We have to make it rotate around the center of the Y-axis 182 00:13:58.524 --> 00:14:00.674 So hey angle, out of the things you have 183 00:14:00.674 --> 00:14:03.624 What are you going to do to the y value? You have to accumulate it 184 00:14:03.624 --> 00:14:10.424 How? Multiply the angular velocity to mouse_X 185 00:14:10.424 --> 00:14:14.474 And multiply Time.deltaTime 186 00:14:15.674 --> 00:14:20.074 And bring over the current angle to angle 187 00:14:20.074 --> 00:14:24.574 It would be modified due to mouse_X and mouse_Y 188 00:14:25.474 --> 00:14:31.024 Re-set the modified value to the angle value 189 00:14:31.024 --> 00:14:32.274 That is number 3 190 00:14:33.274 --> 00:14:35.324 So hey current transform, 191 00:14:35.324 --> 00:14:38.074 What am I going to do for your eulerAngles value? 192 00:14:38.074 --> 00:14:40.124 I will choose angle value 193 00:14:42.124 --> 00:14:46.274 But if we do this, and move the mouse up and down 194 00:14:46.274 --> 00:14:49.824 It will turn over to the back 195 00:14:49.824 --> 00:14:55.774 Therefore, for cases of rotating as if nodding up and down 196 00:14:55.774 --> 00:14:58.774 I will regulate the angle 197 00:15:00.674 --> 00:15:05.574 In conclusion, before rotating the camera in the rotation direction 198 00:15:05.574 --> 00:15:14.324 Third, there needs to be a regulation for up and down rotation 199 00:15:14.324 --> 00:15:21.674 I will regulate it from -80 to 80 degrees 200 00:15:22.674 --> 00:15:28.724 Hey if angle, what if your x value becomes smaller than that? 201 00:15:28.724 --> 00:15:33.774 What am I going to do if it gets smaller than -80? 202 00:15:33.774 --> 00:15:39.424 I would fix the angle.x value to -80 203 00:15:39.424 --> 00:15:44.374 If it has become -90 degrees by moving up and down 204 00:15:44.374 --> 00:15:46.974 It would be smaller than -80, then what? 205 00:15:46.974 --> 00:15:49.874 I would force it to be a -80 degrees 206 00:15:50.824 --> 00:15:53.674 Next, this time let's do the else if 207 00:15:53.674 --> 00:15:57.074 Hey angle, if your x value gets bigger than what? 208 00:15:57.074 --> 00:16:02.374 What? If it gets bigger than 80 degrees? 209 00:16:02.374 --> 00:16:04.174 The x value that the angle has 210 00:16:04.174 --> 00:16:07.324 will be fixed to the value of 80 211 00:16:08.624 --> 00:16:14.174 Let's leave it there and come back to the unity engine editor 212 00:16:14.174 --> 00:16:15.974 I will try to play it 213 00:16:17.274 --> 00:16:19.674 So if I lift the mouse upwards 214 00:16:19.674 --> 00:16:21.424 The camera view goes downwards 215 00:16:21.424 --> 00:16:24.924 And if I pull the mouse downwards, the view goes up 216 00:16:24.924 --> 00:16:26.724 But it gets odd 217 00:16:28.324 --> 00:16:32.824 If I lift up a little, the viewpoint strikes to the surface 218 00:16:32.824 --> 00:16:35.024 The left and right is fine 219 00:16:35.824 --> 00:16:40.674 For the first question, something is wrong with the direction 220 00:16:40.674 --> 00:16:43.824 If the mouse is lifted upwards, it should be looking up 221 00:16:43.824 --> 00:16:45.574 But the view is facing downwards 222 00:16:45.574 --> 00:16:47.924 And if I pull the mouse downwards 223 00:16:47.924 --> 00:16:49.524 the view should be downwards as well 224 00:16:49.524 --> 00:16:51.874 But it suddenly changes while trying to look upwards 225 00:16:52.624 --> 00:16:57.674 Since it moves up and down depending on the mouse_Y value 226 00:16:57.674 --> 00:17:01.424 Through the usage of substitution instead of addition 227 00:17:01.424 --> 00:17:04.174 We will try to make it operate in reverse 228 00:17:05.674 --> 00:17:07.624 And let's check once again 229 00:17:09.924 --> 00:17:13.874 The view heads upwards and downwards depending on the movement of the mouse 230 00:17:13.874 --> 00:17:15.124 But it cannot cross this horizontal line 231 00:17:15.124 --> 00:17:16.274 What happens if it is kept on lifted upwards? 232 00:17:16.274 --> 00:17:20.774 It strikes down and faces down once again 233 00:17:20.774 --> 00:17:22.674 The reason is because 234 00:17:23.874 --> 00:17:29.874 Internally, unity does not use negative numbers for angles 235 00:17:31.074 --> 00:17:35.674 Lets say the angle was 0,0,0 236 00:17:35.674 --> 00:17:40.524 It faces upwards the moment the mouse is lifted up 237 00:17:40.524 --> 00:17:42.724 If we lift it up, it becomes a negative number value 238 00:17:43.674 --> 00:17:47.124 Let's say that it has become -10 239 00:17:47.124 --> 00:17:52.024 Then the x value will be -10,0,0 240 00:17:52.024 --> 00:17:55.174 It would have to rotate as much as -10 degrees 241 00:17:55.174 --> 00:17:58.324 In unity, this is modified to 242 00:17:58.324 --> 00:18:02.224 What is 360 - 10? It is 350 243 00:18:02.224 --> 00:18:05.874 350 degrees and -10 degrees stand for the same value 244 00:18:05.874 --> 00:18:09.774 So internally, it is modified to a value of 350 245 00:18:11.074 --> 00:18:12.374 Then what happens? 246 00:18:12.374 --> 00:18:19.174 The 350x gets caught in this condition 247 00:18:19.174 --> 00:18:19.824 Then what? 248 00:18:19.824 --> 00:18:22.774 It's forced to be modified into 80 degrees 249 00:18:22.774 --> 00:18:24.624 It will lead to this phenomenon 250 00:18:25.424 --> 00:18:27.974 Therefore, in order to solve this problem 251 00:18:27.974 --> 00:18:33.124 Instead of modifying the original angle 252 00:18:33.124 --> 00:18:35.874 We will have a variable that 253 00:18:35.874 --> 00:18:38.324 calculates the angle from the beginning 254 00:18:39.474 --> 00:18:41.974 Let's change it to that way 255 00:18:43.774 --> 00:18:49.474 First, I will make a variable that can hold 256 00:18:49.474 --> 00:18:52.224 the rotation value that is calculated by the global variable 257 00:18:52.224 --> 00:18:55.624 I will make float mx = 0 258 00:18:55.624 --> 00:19:00.824 And float my = 0 as well 259 00:19:02.374 --> 00:19:05.174 I will come to the bottom 260 00:19:05.174 --> 00:19:08.974 and erase this angle instead of bringing it over 261 00:19:08.974 --> 00:19:15.074 Then the angle.x value will be reformed to mx 262 00:19:15.074 --> 00:19:18.874 And what should the angle.y value be? my 263 00:19:18.874 --> 00:19:22.174 We are accumulating it to the variables that we have made 264 00:19:22.924 --> 00:19:28.274 And then change angle.x to mx 265 00:19:38.024 --> 00:19:39.824 Next lastly, for number 4 266 00:19:39.824 --> 00:19:42.524 Using this mx and my 267 00:19:42.524 --> 00:19:45.124 We will set it with a new angle 268 00:19:46.224 --> 00:19:49.324 So using the keyword 'new' instead of angle 269 00:19:49.324 --> 00:19:52.024 I will create a new vector 270 00:19:52.024 --> 00:19:58.074 Open brackets and the x value is mx, y value is my 271 00:19:58.074 --> 00:20:02.224 Then z will be set with the value of 0 272 00:20:02.224 --> 00:20:05.424 In this case, mx and my value 273 00:20:05.424 --> 00:20:07.774 does not need to be modified to a positive number, when it is a negative number 274 00:20:07.774 --> 00:20:12.824 Because it is being accumulated to 275 00:20:12.824 --> 00:20:14.274 the place where we have made a global variable 276 00:20:14.274 --> 00:20:16.124 What do we do with this accumulated value? 277 00:20:16.124 --> 00:20:20.624 We are just setting newly into the angle 278 00:20:21.474 --> 00:20:24.874 Let's save this and play once again 279 00:20:26.424 --> 00:20:28.824 Now when it's lifted upwards, it is looking up at the sky 280 00:20:28.824 --> 00:20:31.424 If it's moved to the bottom, the view moves down as well 281 00:20:32.524 --> 00:20:35.074 And if it is moved upwards, it doesn't go up any more 282 00:20:35.074 --> 00:20:37.174 It doesn't get bigger than 80 degrees 283 00:20:37.174 --> 00:20:40.524 Same for the bottom, it doesn't turn over anymore 284 00:20:41.074 --> 00:20:46.674 Instead, we can see that it is rotating well in 360 degrees 285 00:20:49.224 --> 00:20:52.174 In the CamRotate script, we have 286 00:20:52.174 --> 00:20:54.924 regulated the up and down rotation 287 00:20:54.924 --> 00:21:00.524 This is setting the minimum and maximum value 288 00:21:00.524 --> 00:21:02.974 It doesn't get smaller than the minimum value 289 00:21:02.974 --> 00:21:07.424 And it is regulated to not get bigger than the maximum value 290 00:21:08.124 --> 00:21:11.774 There is a function that plays this role 291 00:21:11.774 --> 00:21:19.724 A function called Clamp inside a structure called Mathf 292 00:21:20.324 --> 00:21:25.424 The first argument value inside the bracket is mx value 293 00:21:25.424 --> 00:21:30.224 Then the second argument value is the minimum value of -80 294 00:21:30.224 --> 00:21:35.124 Next, the third argument value is the maximum value of 80 295 00:21:35.124 --> 00:21:38.574 For example, let's say the mx has become -90 296 00:21:38.574 --> 00:21:42.024 Then it is smaller than the minimum value 297 00:21:42.024 --> 00:21:44.774 So what happens to this? 298 00:21:44.774 --> 00:21:48.274 It gets the value of -80 299 00:21:48.974 --> 00:21:52.424 The mx value isn't the one changing 300 00:21:52.424 --> 00:21:55.974 Whether it is smaller than then minimum value based on the mx value 301 00:21:55.974 --> 00:21:59.074 or bigger than the maximum value has to be checked 302 00:21:59.074 --> 00:22:04.224 If it is smaller than the minimum value, it returns the minimum value 303 00:22:05.024 --> 00:22:10.374 For the opposite case, let's say the mx has become a 90 304 00:22:10.374 --> 00:22:11.774 Then it is bigger than the maximum value 305 00:22:11.774 --> 00:22:15.374 So what number does the Clamp function return? 306 00:22:15.374 --> 00:22:17.774 It returns the value of 80 307 00:22:18.624 --> 00:22:21.574 Now, it has become a 70 308 00:22:21.574 --> 00:22:26.624 So it is not smaller than the minimum value and is not bigger than the maximum value 309 00:22:26.624 --> 00:22:31.624 How much does the Clamp function return? It returns 70 310 00:22:31.624 --> 00:22:34.174 This mx isn't the one being modified 311 00:22:35.274 --> 00:22:42.724 So when it is smaller than the minimum value and bigger than maximum value 312 00:22:42.724 --> 00:22:45.474 Where should the value that is given by this function be set? 313 00:22:45.474 --> 00:22:49.674 It is overwriting the setting on the mx 314 00:22:49.674 --> 00:22:55.624 The if condition can be organized into a single sentence 315 00:22:55.624 --> 00:22:57.224 I will erase the top 316 00:22:58.824 --> 00:23:03.624 This time, let's rotate the Player 317 00:23:03.624 --> 00:23:08.224 The player will only be rotated 318 00:23:08.224 --> 00:23:10.024 based on the left and right movement of the mouse 319 00:23:11.524 --> 00:23:13.774 Select the Scripts folder 320 00:23:13.774 --> 00:23:16.174 Press the (+) button on the project tab 321 00:23:16.174 --> 00:23:18.424 Create a C# Script 322 00:23:18.424 --> 00:23:22.174 Let's name this PlayerRotate 323 00:23:25.424 --> 00:23:29.324 Check that this script is assembled into the 324 00:23:29.324 --> 00:23:34.874 Player game object through a drag and drop 325 00:23:34.874 --> 00:23:36.974 Double click on it to open 326 00:23:37.724 --> 00:23:40.424 Make it equivalent to CamRotate 327 00:23:40.424 --> 00:23:44.224 But you have to eliminate every rotation value about mx 328 00:23:44.224 --> 00:23:47.524 Make sure it is only rotating left and right 329 00:23:49.424 --> 00:23:52.524 First, you need a rotation velocity 330 00:23:52.524 --> 00:23:57.674 Then, there needs to be a variable to save the rotation value 331 00:23:58.624 --> 00:24:07.474 So public float rotSpeed = 200 332 00:24:07.474 --> 00:24:13.595 Next, float my = 0 to save the rotation value 333 00:24:15.074 --> 00:24:18.174 We have to receive the user input 334 00:24:19.174 --> 00:24:24.924 Using the variable called float, mouse_X = 335 00:24:24.924 --> 00:24:30.524 Hey Input, use the GetAxis function you have 336 00:24:30.524 --> 00:24:33.574 Over here, leave a space between Mouse and X 337 00:24:33.574 --> 00:24:35.724 Leaving a space is an essential 338 00:24:38.124 --> 00:24:41.424 And then accumulate the rotation value to my 339 00:24:41.424 --> 00:24:51.774 += and then mouse_X multiplied by rotSpeed 340 00:24:51.774 --> 00:24:57.324 Next, multiply Time.deltaTime which is the time value 341 00:24:58.423 --> 00:25:03.023 The following step is for the rotation value called my 342 00:25:03.023 --> 00:25:05.323 Set it to the Player game object 343 00:25:05.323 --> 00:25:08.923 which PlayerRotate script is attached to 344 00:25:09.823 --> 00:25:12.173 So hey transform, 345 00:25:12.173 --> 00:25:14.573 What are we going to do to the eulerAngles value you have? 346 00:25:14.573 --> 00:25:18.023 I made a new vector and finished the setting 347 00:25:18.023 --> 00:25:25.873 0 for x, my for y, 0 for z 348 00:25:25.873 --> 00:25:31.473 Let me check. If you press play 349 00:25:31.473 --> 00:25:34.523 When you move left and right, you can see the camera is rotating 350 00:25:34.523 --> 00:25:37.673 But you cannot see the Player rotating 351 00:25:38.123 --> 00:25:41.173 Select Player from the hierarchy and press the right 352 00:25:41.173 --> 00:25:44.223 Insert a cube from the 3D object 353 00:25:44.223 --> 00:25:46.173 I will name this Eye 354 00:25:47.023 --> 00:25:50.723 Bring it over using object focusing 355 00:25:50.723 --> 00:25:58.423 Utilize scale tool to make it equivalent to what I have made 356 00:25:58.423 --> 00:26:01.323 Hold the blue axis and bring it forwards 357 00:26:01.323 --> 00:26:04.573 Make it so that it looks like 358 00:26:04.573 --> 00:26:07.173 as if it is wearing sunglasses 359 00:26:08.323 --> 00:26:13.223 It is expressed this way to show that it is the front side 360 00:26:13.723 --> 00:26:15.123 Create a material 361 00:26:15.123 --> 00:26:18.223 And I will put it in the sunglasses part 362 00:26:19.023 --> 00:26:22.873 Select Materials folder from the project tab 363 00:26:22.873 --> 00:26:25.673 Choose MatGround which has already been made 364 00:26:25.673 --> 00:26:29.023 If you press Ctrl + D, it is copied 365 00:26:29.523 --> 00:26:34.023 Name this MatEye 366 00:26:34.023 --> 00:26:36.373 I will color it black since it is sunglasses 367 00:26:36.373 --> 00:26:40.673 Select the color from the Base Map of inspector 368 00:26:40.673 --> 00:26:42.573 I will color it black 369 00:26:42.573 --> 00:26:46.223 You can change it to the color of your preference 370 00:26:46.223 --> 00:26:52.023 Next, select Eye which is chosen as the child of the Player 371 00:26:52.023 --> 00:26:55.523 In the Materials of Mesh Renderer, instead of Lit 372 00:26:55.523 --> 00:26:58.573 Drag MatEye and drop 373 00:26:59.873 --> 00:27:03.673 Then it would turn out as if it is wearing sunglasses 374 00:27:05.073 --> 00:27:06.723 If you move the mouse to the left 375 00:27:06.723 --> 00:27:09.123 The character rotates 376 00:27:09.123 --> 00:27:10.723 as you can see from the scene view 377 00:27:12.123 --> 00:27:18.923 You can see that the camera and the player is both rotating 378 00:27:21.523 --> 00:27:24.473 In order to create the form of FPS 379 00:27:24.473 --> 00:27:26.423 Locate it to the eye 380 00:27:26.423 --> 00:27:29.023 or we have to make it locate to the head 381 00:27:31.123 --> 00:27:35.923 Then if the player moves, make the camera follow along 382 00:27:35.923 --> 00:27:39.573 We have to make sure it follows the Player around 383 00:27:41.223 --> 00:27:45.673 So select Player game object, and press right 384 00:27:45.673 --> 00:27:50.473 Create a new game object called Create Empty 385 00:27:51.173 --> 00:27:54.323 I will name this as CamPosition 386 00:27:56.073 --> 00:28:03.073 And the y value of the position in the inspector will be 1.2 387 00:28:04.073 --> 00:28:06.923 In the location that is a little bit higher than the head 388 00:28:06.923 --> 00:28:09.473 the camera will be following along 389 00:28:10.573 --> 00:28:14.523 A script will be made 390 00:28:14.523 --> 00:28:16.723 which makes the CamPosition follow along every second 391 00:28:16.723 --> 00:28:20.973 Press the (+) button from the project tab and then C#Script 392 00:28:20.973 --> 00:28:26.423 I will name this CamFollow 393 00:28:27.623 --> 00:28:29.873 This game object called CamPosition 394 00:28:29.873 --> 00:28:31.973 Who should be following this around? 395 00:28:32.973 --> 00:28:34.973 The main camera has to follow it 396 00:28:34.973 --> 00:28:39.873 So this CamFollow script that is currently made 397 00:28:39.873 --> 00:28:42.073 has to be attached to the main camera 398 00:28:42.073 --> 00:28:45.323 So drag CamFollow 399 00:28:45.323 --> 00:28:48.473 and attach it to the main camera 400 00:28:48.473 --> 00:28:51.273 Make sure that it is assembled 401 00:28:51.923 --> 00:28:55.623 Double click CamFollow to open it up 402 00:28:55.623 --> 00:29:00.173 It has to keep on following CamPosition 403 00:29:00.173 --> 00:29:02.414 so it needs to be implemented in an updated version 404 00:29:03.973 --> 00:29:11.273 The goal is to keep on following the target 405 00:29:11.273 --> 00:29:16.073 What is the target? It is CamPosition 406 00:29:16.073 --> 00:29:24.423 A variable that will hold the transform which is the target 407 00:29:25.723 --> 00:29:32.623 So the public data type will be transform 408 00:29:32.623 --> 00:29:35.073 The name of the variable will be target 409 00:29:36.673 --> 00:29:38.773 What I will be inserting over here is 410 00:29:38.773 --> 00:29:43.023 I will drag the transform of CamPosition and insert it in 411 00:29:44.423 --> 00:29:47.173 Next, what happens after the update is 412 00:29:47.173 --> 00:29:51.773 Hey transform, what will be my position? 413 00:29:51.773 --> 00:29:55.623 Write down the code in the sense that 414 00:29:55.623 --> 00:30:01.223 the position value of the transform which I have to follow, will be inserted 415 00:30:01.223 --> 00:30:05.673 If this continues, the position value of the target 416 00:30:05.673 --> 00:30:08.473 and the position value of the target will turn out how? It will become the same 417 00:30:09.023 --> 00:30:13.173 If this target moves, it means the camera will be following 418 00:30:14.273 --> 00:30:17.423 Come back to the editor 419 00:30:17.423 --> 00:30:20.623 Select the main camera 420 00:30:20.623 --> 00:30:24.673 If you look at CamFollow, the target will say None 421 00:30:24.673 --> 00:30:27.423 What do we need to put in here? 422 00:30:27.423 --> 00:30:30.973 Drag the CamPosition from the hierarcy 423 00:30:30.973 --> 00:30:34.173 and it needs to be inserted here 424 00:30:36.673 --> 00:30:39.773 I will try to play it in this case 425 00:30:39.773 --> 00:30:42.073 Move it left and right like so 426 00:30:42.073 --> 00:30:45.923 I will move the character in the scene view 427 00:30:45.923 --> 00:30:48.273 If the Player is moved, you can see that 428 00:30:48.273 --> 00:30:51.873 the camera icon will follow and move along 429 00:30:53.373 --> 00:30:57.423 Character movement 430 00:30:58.923 --> 00:31:02.223 Now, we will try to move the character 431 00:31:04.723 --> 00:31:07.273 I will develop a script 432 00:31:08.823 --> 00:31:11.873 In the Assets folder of the project tab 433 00:31:11.873 --> 00:31:14.523 select the Scripts folder 434 00:31:14.523 --> 00:31:18.473 Press the (+) button and choose C#Script 435 00:31:18.473 --> 00:31:23.923 Name it to PlayerMove 436 00:31:25.823 --> 00:31:29.073 If it is finished, from the hierarchy 437 00:31:29.073 --> 00:31:32.673 choose Player game object 438 00:31:32.673 --> 00:31:36.473 Drag and drop the PlayerMove that has just been made 439 00:31:37.973 --> 00:31:43.173 And then double click to open up the PlayerMove script 440 00:31:45.173 --> 00:31:48.373 I will get the input of the user 441 00:31:48.373 --> 00:31:53.323 Decide the direction based on the value that has been input 442 00:31:53.323 --> 00:31:56.173 And try to move it towards that direction 443 00:31:58.923 --> 00:32:04.823 First, let's receive the input of the user 444 00:32:05.523 --> 00:32:13.123 Over here, when W,A,S,D has been entered 445 00:32:13.123 --> 00:32:16.673 the value will be held in this variable 446 00:32:16.673 --> 00:32:26.023 And then the movement direction will be set based on the value that has been received 447 00:32:27.473 --> 00:32:33.923 Next, move to the direction that has been decided in number 2 448 00:32:35.623 --> 00:32:38.273 Let's receive W,A,S,D key input 449 00:32:38.273 --> 00:32:45.173 First, I will receive the value for the key A and D 450 00:32:45.173 --> 00:32:48.673 Create a variable called float h and over here 451 00:32:48.673 --> 00:32:53.123 Hey input, based on the functions you have 452 00:32:53.123 --> 00:32:57.773 It can be received through a function called GetAxis 453 00:32:58.523 --> 00:33:02.673 Over here, parameter called Hotizontal 454 00:33:04.323 --> 00:33:10.923 This time, I will receive the value of key W and S 455 00:33:10.923 --> 00:33:15.923 In case of float v, hey input out of what you have 456 00:33:15.923 --> 00:33:19.173 It can be received through GetAxis function once again 457 00:33:19.173 --> 00:33:24.723 This time, the parameter is different, Vertical 458 00:33:27.023 --> 00:33:31.423 If key A is pressed for variable h, then -1 459 00:33:31.423 --> 00:33:33.873 then if key D is pressed, the value is +1 460 00:33:33.873 --> 00:33:36.323 If nothing is pressed, it will be set to 0 461 00:33:36.823 --> 00:33:41.723 For v, if W is pressed then +1 Next, if S is pressed then -1 462 00:33:41.723 --> 00:33:44.623 If nothing is pressed, it will be set to 0 463 00:33:46.023 --> 00:33:48.423 I will create a variable that will hold the movement direction 464 00:33:48.423 --> 00:33:52.973 I will name it as dir of Vector3 465 00:33:54.223 --> 00:33:58.823 Over here hey Vector 3, out of what you have 466 00:33:58.823 --> 00:34:03.823 Value h will be multiplied to a value called right 467 00:34:03.823 --> 00:34:10.123 Then, to + Vector3.forward value 468 00:34:10.123 --> 00:34:12.473 v will be multiplied 469 00:34:14.823 --> 00:34:18.823 The value inside Vector3.right is 470 00:34:20.423 --> 00:34:25.473 1 for x, 0 for y, and 0 for z 471 00:34:25.473 --> 00:34:27.523 I have multiplied h over here 472 00:34:27.523 --> 00:34:29.473 Then this value will be 473 00:34:31.173 --> 00:34:37.073 multiplying h for each x,y,and z 474 00:34:37.073 --> 00:34:42.023 Then what happens? It will be h,0,0 475 00:34:43.023 --> 00:34:47.423 For Vector3.forward multiplied by v 476 00:34:47.423 --> 00:34:49.423 I will try to express it this way 477 00:34:51.323 --> 00:34:56.073 For Vector3.forward, it is 0 for x as well as y 478 00:34:56.073 --> 00:34:58.973 A value of 1 for z is held inside 479 00:34:58.973 --> 00:35:03.523 If v is multiplied, as you can see in the bottom 480 00:35:03.523 --> 00:35:06.723 You can multiply v for each argument 481 00:35:06.723 --> 00:35:10.423 Then it would be 0,0,v 482 00:35:13.123 --> 00:35:19.123 If you add h,0,0 and 0,0,v What is the result? 483 00:35:21.223 --> 00:35:29.223 A value of h,0,v will be the result of the Vector 484 00:35:30.673 --> 00:35:34.023 If we press key D 485 00:35:34.023 --> 00:35:37.673 and insert value 1 for h 486 00:35:37.673 --> 00:35:39.973 Then if v has not been pressed 487 00:35:39.973 --> 00:35:43.923 So the value of 0 has been inserted 488 00:35:43.923 --> 00:35:50.523 Then how will h,0,v be modified? It would be 1,0,0 489 00:35:50.523 --> 00:35:55.323 What does this point at? It points toward the right side 490 00:35:55.323 --> 00:35:56.523 So what next? 491 00:35:57.623 --> 00:36:01.673 In number 3, the dir direction is in the right side 492 00:36:01.673 --> 00:36:04.723 It leads to the result of it moving towards the right 493 00:36:06.023 --> 00:36:09.173 In reverse, h has the value of 0 494 00:36:09.173 --> 00:36:12.073 And v has the value of 1 495 00:36:12.073 --> 00:36:17.623 How does this end up? It would be 0,0,1 496 00:36:17.623 --> 00:36:22.723 This leads to the Vector that shows the front direction 497 00:36:24.373 --> 00:36:28.773 This time, let's say h and v both has the value of 1 498 00:36:28.773 --> 00:36:32.023 Then it would be 1,0,1 499 00:36:32.023 --> 00:36:37.773 This would receive the result of addition between the right Vector and the front Vector 500 00:36:37.773 --> 00:36:42.773 When these two Vectors are added 501 00:36:42.773 --> 00:36:47.223 It leads to a diagonal direction which points to the right front direction 502 00:36:47.973 --> 00:36:52.473 According to this calculation, the dir decides the direction 503 00:36:54.173 --> 00:36:58.023 if the direction has been set, I will try to move in that direction 504 00:36:59.173 --> 00:37:04.123 I will accumulate the position value of the transform and the current value 505 00:37:04.123 --> 00:37:10.523 += and dir multiplied by speed value 506 00:37:10.523 --> 00:37:13.523 We have not set it to a variable 507 00:37:13.523 --> 00:37:16.723 We will choose a random value of 7 and modify it later 508 00:37:16.723 --> 00:37:20.623 Multiplied by Time.deltaTime 509 00:37:22.923 --> 00:37:27.223 I will create a variable that holds the velocity value 510 00:37:28.623 --> 00:37:39.973 The velocity which is public float moveSpeed 511 00:37:39.973 --> 00:37:42.173 will be set to 7 512 00:37:42.173 --> 00:37:44.873 The number 7 which is inside the update 513 00:37:44.873 --> 00:37:47.423 will be replaced to moveSpeed 514 00:37:51.573 --> 00:37:53.373 Make sure to save everything 515 00:37:53.373 --> 00:37:57.873 Come back to the editor and try to play it 516 00:37:59.423 --> 00:38:03.573 It moves forward when pressing W, it moves backward when pressing S 517 00:38:03.573 --> 00:38:07.273 And moves right if D is pressed 518 00:38:07.273 --> 00:38:10.673 You can also see that it moves left when pressing A 519 00:38:13.173 --> 00:38:14.773 However, the odd part is 520 00:38:14.773 --> 00:38:19.173 I will move the mouse and face the left side 521 00:38:19.173 --> 00:38:21.573 On the top, I'm facing left 522 00:38:21.573 --> 00:38:28.823 When I press W, it should be moving in this direction 523 00:38:28.823 --> 00:38:30.873 I will press W 524 00:38:30.873 --> 00:38:36.923 But now, it doesn't move in the direction of this red sign 525 00:38:36.923 --> 00:38:40.473 In the scene view, on the right upper side 526 00:38:40.473 --> 00:38:42.923 It's moving in the gizmo direction 527 00:38:43.623 --> 00:38:47.473 If D is pressed, the red gizmo on the upper right 528 00:38:47.473 --> 00:38:51.373 It moves toward the X-axis 529 00:38:53.023 --> 00:38:54.523 There are problems like so 530 00:38:55.473 --> 00:38:59.273 So we need to let it move to the direction that the Player is facing or 531 00:38:59.273 --> 00:39:02.773 based on the direction that the camera is facing 532 00:39:02.773 --> 00:39:05.823 We need to let it move after the direction has been set 533 00:39:07.473 --> 00:39:14.673 As I mentioned before, according to the gizmo direction on the upper right side 534 00:39:14.673 --> 00:39:17.323 The blue axis direction will be over here 535 00:39:17.323 --> 00:39:20.973 Then, the red axis direction is here 536 00:39:22.423 --> 00:39:27.823 This direction which is referred as the gizmo's red axis 537 00:39:27.823 --> 00:39:34.673 It is the value of Vector3.right 538 00:39:34.673 --> 00:39:36.523 Then the blue axis direction is 539 00:39:36.523 --> 00:39:43.123 the value of Vector3.forward 540 00:39:43.123 --> 00:39:46.573 This stands for the x as 0,0,1 541 00:39:46.573 --> 00:39:52.773 And the Vector3.right is 1,0,0 542 00:39:52.773 --> 00:39:57.423 So until now, we have made it move in the 543 00:39:57.423 --> 00:39:59.923 direction of the gizmo which is placed on the upper right side 544 00:39:59.923 --> 00:40:03.973 This is called world coordinates 545 00:40:04.823 --> 00:40:09.623 The player is currently facing this side but 546 00:40:09.623 --> 00:40:13.423 I will control it so that it would face the other side 547 00:40:14.673 --> 00:40:17.573 Then if we press W 548 00:40:17.573 --> 00:40:20.473 Instead of moving in the direction of Vector3.foward 549 00:40:20.473 --> 00:40:24.123 It would move in the direction which the Player is facing 550 00:40:24.123 --> 00:40:27.723 Next, if I press key D 551 00:40:27.723 --> 00:40:30.323 It would have to move to the right 552 00:40:30.323 --> 00:40:33.473 based on the direction that the Player is facing 553 00:40:33.473 --> 00:40:37.173 So let's change the value like so 554 00:40:37.173 --> 00:40:40.423 This is called relative coordinates 555 00:40:41.873 --> 00:40:46.523 In Vector3.right, it includes the direction of the world 556 00:40:46.523 --> 00:40:52.673 But now, based on the direction that the Player is facing 557 00:40:52.673 --> 00:40:55.973 Instead of Vector3, it needs to be modified to 558 00:40:55.973 --> 00:40:59.023 transform which starts with a lower case 559 00:41:01.423 --> 00:41:05.723 Now, when pressing W and S, it moves well 560 00:41:05.723 --> 00:41:11.973 I will rotate the camera to the left and press W 561 00:41:11.973 --> 00:41:15.423 Like so, you can see that it rotates in the direction that it is facing 562 00:41:15.423 --> 00:41:17.323 If key D is pressed 563 00:41:17.323 --> 00:41:20.573 The right side which the Player is currently facing 564 00:41:20.573 --> 00:41:21.573 If key A is pressed 565 00:41:21.573 --> 00:41:24.773 Based on the direction which the Player is facing 566 00:41:24.773 --> 00:41:27.572 You can see that it moves to the left 567 00:41:28.772 --> 00:41:31.772 Because you cannot clearly see whether it is moving 568 00:41:31.772 --> 00:41:36.122 I will insert a huge cube in the center 569 00:41:36.122 --> 00:41:39.022 Press the (+) button from the hierarchy 570 00:41:39.022 --> 00:41:41.872 Set Cube from the 3D object 571 00:41:41.872 --> 00:41:44.572 I will name it as Wall 572 00:41:45.172 --> 00:41:50.622 Then insert 0,0,0 for the location 573 00:41:50.622 --> 00:41:52.972 Move it slightly to the front 574 00:41:55.422 --> 00:41:58.672 Press the key R to change to the scale tool 575 00:41:58.672 --> 00:42:03.072 Scale it properly 576 00:42:08.172 --> 00:42:10.422 If you play again after finishing it 577 00:42:10.422 --> 00:42:13.022 The rotation of the camera or the movement 578 00:42:13.022 --> 00:42:15.372 will be easy to take a look at 579 00:42:16.122 --> 00:42:19.122 When rotating the camera by moving the mouse 580 00:42:19.122 --> 00:42:21.172 or when rotating the Player 581 00:42:21.172 --> 00:42:24.972 It is able to be expressed visibly due to the wall 582 00:42:24.972 --> 00:42:29.872 The movement is expressed visibly as well 583 00:42:34.772 --> 00:42:41.372 First, it was Vector3.right and then it was Vector3.forward 584 00:42:43.072 --> 00:42:45.372 When I calculated it into numbers 585 00:42:45.372 --> 00:42:50.222 What did I say about the results it would lead to? 586 00:42:50.222 --> 00:42:53.972 I mentioned that Vector called h,0,v will be received 587 00:42:55.172 --> 00:42:58.722 So instead of calculating it like so 588 00:42:58.722 --> 00:43:01.122 just create the Vector right away 589 00:43:01.122 --> 00:43:06.222 and insert value h and v as value x and y 590 00:43:07.822 --> 00:43:09.472 Let's change it that way 591 00:43:10.672 --> 00:43:12.822 Make sure to comment it out 592 00:43:12.822 --> 00:43:16.872 Over here in the bottom, create Vector3.dir once again 593 00:43:16.872 --> 00:43:19.572 Now I will create a new Vector 594 00:43:19.572 --> 00:43:23.422 h for the x value and 0 for the y value 595 00:43:23.422 --> 00:43:27.072 Insert value v into z 596 00:43:28.472 --> 00:43:31.872 In this case, it will be moved based on the direction 597 00:43:31.872 --> 00:43:35.372 which is calculated as world coordinate system 598 00:43:35.372 --> 00:43:37.772 It needs to be modified to the relative coordinates 599 00:43:38.672 --> 00:43:49.172 Convert the direction of dir based on the main camera 600 00:43:50.722 --> 00:43:54.072 Let's overwrite on the dir value 601 00:43:54.072 --> 00:44:02.372 Hey main camera, use the functions in your transform 602 00:44:02.372 --> 00:44:06.072 There is a function that changes 603 00:44:06.072 --> 00:44:08.422 the dir world coordinate system to the relative coordinates of the camera 604 00:44:08.422 --> 00:44:11.822 A function called TransformDirection 605 00:44:12.972 --> 00:44:16.372 If dir is inserted as a parameter 606 00:44:16.372 --> 00:44:19.622 The direction that is calculated from world coordinates 607 00:44:19.622 --> 00:44:23.072 will be converted to a direction calculated based on the camera 608 00:44:24.672 --> 00:44:27.472 Coming back to the editor and playing it 609 00:44:28.522 --> 00:44:31.322 We can see that it operates in the same way 610 00:44:34.072 --> 00:44:36.772 But there is another problem 611 00:44:36.772 --> 00:44:40.822 The velocity is equal for moving front and back, left and right 612 00:44:40.822 --> 00:44:42.322 But when moving diagonally 613 00:44:42.322 --> 00:44:45.622 You can see that it moves in a faster velocity 614 00:44:47.172 --> 00:44:50.072 This is a problem that occurs because 615 00:44:50.072 --> 00:44:52.822 the moving Vector is larger when moving diagonally 616 00:44:53.772 --> 00:44:58.622 So we will Normalize dir 617 00:44:58.622 --> 00:45:01.372 Make the size into 1 618 00:45:01.372 --> 00:45:05.672 The size of dir will be 1 619 00:45:05.672 --> 00:45:10.022 It is called Normalization or Normalize 620 00:45:12.122 --> 00:45:15.422 Hey dir, the Normalize that you have 621 00:45:15.422 --> 00:45:18.922 operate the Normalize function which starts with a capital letter 622 00:45:18.922 --> 00:45:22.022 The size of dir will be 1 623 00:45:23.622 --> 00:45:25.172 Let's play it 624 00:45:25.172 --> 00:45:27.272 The movement of right and left 625 00:45:27.272 --> 00:45:30.422 the velocity of moving front and back is equal 626 00:45:30.422 --> 00:45:34.022 Next, it is the same when moved diagonally 627 00:45:36.122 --> 00:45:39.472 This time, when moving the player 628 00:45:39.472 --> 00:45:42.172 We are changing the location by 629 00:45:42.172 --> 00:45:45.822 accumulating the position value of the Player ourselves 630 00:45:45.822 --> 00:45:52.422 But in the unity, there is a component that is specialized in characters 631 00:45:53.222 --> 00:45:56.622 Using this component, 632 00:45:56.622 --> 00:45:59.222 I will try to move the Player 633 00:46:00.572 --> 00:46:04.122 Select the Player game objectt from the hierarchy 634 00:46:04.122 --> 00:46:06.572 Erase Capsule Collider 635 00:46:06.572 --> 00:46:10.922 Press the key on the right, Remove component or 636 00:46:12.722 --> 00:46:15.972 Capsule Collider, there are three dots on the right 637 00:46:15.972 --> 00:46:20.472 Press the three dots to Remove Component 638 00:46:21.422 --> 00:46:25.172 Press the Add Component button from the inspector 639 00:46:25.172 --> 00:46:28.672 Type in Character in the search engine 640 00:46:30.322 --> 00:46:33.422 You can receive the research result of Character Controller 641 00:46:33.422 --> 00:46:36.222 Add the component 642 00:46:37.372 --> 00:46:41.822 This component has the collision area 643 00:46:41.822 --> 00:46:43.872 as well as a moving function 644 00:46:44.722 --> 00:46:46.672 So utilizing the character controller 645 00:46:46.672 --> 00:46:48.772 I will try to move it 646 00:46:49.922 --> 00:46:52.972 Come to PlayerMove script 647 00:46:52.972 --> 00:46:56.372 The variable that will receive the character controller 648 00:46:58.022 --> 00:47:01.022 The data type should be set as character controller 649 00:47:01.022 --> 00:47:02.972 I will name it cc 650 00:47:04.422 --> 00:47:06.772 Through the keyword called public 651 00:47:06.772 --> 00:47:09.972 We can drag and drop from the inspector 652 00:47:09.972 --> 00:47:14.922 The character controller is in the same line as 653 00:47:14.922 --> 00:47:16.822 the PlayerMove that is attached 654 00:47:16.822 --> 00:47:19.772 It can be found through codes 655 00:47:19.772 --> 00:47:23.122 So in the Start function 656 00:47:23.122 --> 00:47:30.622 Let's bring over character controller component 657 00:47:30.622 --> 00:47:32.822 I will insert the value into cc 658 00:47:32.822 --> 00:47:35.972 Using the function called GetComponent 659 00:47:35.972 --> 00:47:40.222 Bring over character controller component 660 00:47:41.622 --> 00:47:44.022 Then in the variable cc 661 00:47:44.022 --> 00:47:46.922 The character controller is all brought over 662 00:47:48.072 --> 00:47:51.772 Using cc, I will modify the move over here 663 00:47:52.622 --> 00:47:55.172 The code that directly revised the position 664 00:47:55.172 --> 00:47:57.222 has to be commented out 665 00:47:57.222 --> 00:48:00.622 In the bottom, hey cc, out of the functions you have 666 00:48:00.622 --> 00:48:02.572 There is a function called Move 667 00:48:02.572 --> 00:48:04.372 Open brackets and over here 668 00:48:05.722 --> 00:48:10.772 dir multiplied by moveSpeed and Time.deltaTime 669 00:48:10.772 --> 00:48:15.622 will lead to movement 670 00:48:17.372 --> 00:48:22.222 If you save it and play, it will move in the same way 671 00:48:27.222 --> 00:48:31.822 And when moved forward, we are not able to pass through this cube 672 00:48:31.822 --> 00:48:34.072 It even has the collision handling function 673 00:48:34.422 --> 00:48:38.322 Now, let's do an overview of what we have studied 674 00:48:38.322 --> 00:48:38.822 Project creation and setting, character rotation 675 00:48:38.822 --> 00:48:39.322 Project creation and setting Ground object; Hierarchy > + > 3D Object > Plane 676 00:48:39.322 --> 00:48:39.822 Player Object: Hierarchy > + > 3D Object > Capsule 677 00:48:39.822 --> 00:48:40.322 Main Camera Object Rotation 678 00:48:40.322 --> 00:48:40.822 Input of the user's mouse input.GetAxis(); Decide the rotation direction based on the input value 679 00:48:40.822 --> 00:48:41.322 Angle regulation for up and down rotation Mathf.Clamp(); Camera rotation into the rotation direction 680 00:48:41.322 --> 00:48:41.822 Player Object Rotation 681 00:48:41.822 --> 00:48:42.322 Main Camera It is equal to the code that deleted the mx value in the object rotation script 682 00:48:42.322 --> 00:48:42.822 First person perspective Holds transform of CamPosition in the variable target 683 00:48:42.822 --> 00:48:43.322 Position value of the target and the camera becomes equal transform.position=target.position; 684 00:48:43.322 --> 00:48:43.872 Character movement 685 00:48:43.872 --> 00:48:44.422 Player movement Receive input of user input.GetAxis(); 686 00:48:44.422 --> 00:48:44.972 Set movement direction Vector3dir=newVector3(h,0,v) 687 00:48:44.972 --> 00:48:45.522 Move: key W -> front, key S -> back, key D -> right, key A -> left 688 00:48:45.522 --> 00:48:46.072 has a world coordinates, change Vector3 to relative coordinates using TransformDirection() function 689 00:48:46.072 --> 00:48:46.672 Invoke Normalize() function in order to normalize the size of dir into 1 690 00:48:46.672 --> 00:48:47.222 Player movement using the component Erase Capsule Collider of the Player 691 00:48:47.222 --> 00:48:47.772 Click on Add Component and insert Character Controller 692 00:48:47.772 --> 00:48:48.322 Operate movement and collision handling