1 00:00:00,400 --> 00:00:05,690 We saw that with Input.get_vector, we can get a direction vector. 2 00:00:05,720 --> 00:00:08,571 Let's look at what the function outputs for us. 3 00:00:09,250 --> 00:00:12,620 This little demo shows the output of the function. 4 00:00:12,650 --> 00:00:16,300 If we don't press anything, we get a vector of length zero. 5 00:00:16,330 --> 00:00:19,660 Now, if I press up, I get a vector pointing up. 6 00:00:19,690 --> 00:00:24,900 If I press D, it points to the right, and with W and D it points to the top right. 7 00:00:24,920 --> 00:00:28,099 Now the important part here is how you can see 8 00:00:28,299 --> 00:00:31,140 the length of the vector is always the same. 9 00:00:31,170 --> 00:00:34,300 To be precise, it's limited to one. 10 00:00:34,320 --> 00:00:37,529 This makes it so whether we're trying to move vertically, 11 00:00:37,530 --> 00:00:39,580 horizontally or diagonally, 12 00:00:39,610 --> 00:00:45,420 the ship or whatever you are moving will move at a consistent speed. 13 00:00:45,450 --> 00:00:48,271 This is the purpose of a direction vector. 14 00:00:49,210 --> 00:00:54,740 Now, when you don't have any input, the vector has a length of zero. 15 00:00:54,770 --> 00:00:59,260 And the math with that works similar to what you learned at school. 16 00:00:59,290 --> 00:01:01,980 Zero times anything is equal to zero. 17 00:01:02,010 --> 00:01:07,980 A vector two of length zero, times anything is a vector two of length zero. 18 00:01:08,010 --> 00:01:12,196 As a result, the character will have no velocity and not move. 19 00:01:12,396 --> 00:01:14,380 Or the ship in our case. 20 00:01:14,410 --> 00:01:16,180 I want to show you another thing. 21 00:01:16,210 --> 00:01:19,540 This function gives us support for analog input. 22 00:01:19,570 --> 00:01:21,850 You can see the gamepad in the top right. 23 00:01:21,880 --> 00:01:27,020 Notice how when I move the joystick, the vector changes direction and length, 24 00:01:27,050 --> 00:01:31,100 and this time it can be a bit shorter than before. 25 00:01:31,130 --> 00:01:33,060 Analog input is just that. 26 00:01:33,090 --> 00:01:38,014 It's the ability to control the length of our direction vector 27 00:01:38,371 --> 00:01:42,140 to make the ship move faster or slower. 28 00:01:42,170 --> 00:01:46,114 And Input.get_vector will take care of that for you. 29 00:01:47,210 --> 00:01:50,995 So you can get both keyboard input support 30 00:01:51,195 --> 00:01:55,320 like this, or you can get gamepad input support.