﻿1
00:00:04,350 --> 00:00:05,400
‫Hello and welcome.

2
00:00:05,400 --> 00:00:10,830
‫In this lecture, we're going to be trying to understand a little bit more about these vector structs

3
00:00:10,830 --> 00:00:16,410
‫and the mathematics that underpins them, so that by the end of this lecture you will feel comfortable

4
00:00:16,410 --> 00:00:22,110
‫adding and subtracting vectors as well as multiplying them by floating point values.

5
00:00:22,110 --> 00:00:23,160
‫Let's dive in.

6
00:00:24,230 --> 00:00:30,470
‫So soon, we're going to want to start setting our impulse in the correct rotated direction.

7
00:00:30,470 --> 00:00:36,380
‫But before we do that, we need to understand a little bit more about the mathematics that underlies

8
00:00:36,380 --> 00:00:37,400
‫vectors.

9
00:00:37,430 --> 00:00:43,670
‫Now, in this video, I'm going to be giving you a whistle stop tour of vector mathematics.

10
00:00:43,670 --> 00:00:50,480
‫But if you want some more in-depth explanations, then we have a whole course on maths for game development,

11
00:00:50,480 --> 00:00:52,520
‫which I would highly recommend.

12
00:00:52,670 --> 00:00:58,790
‫Vectors are essentially a mathematical concept and they're quite simple when you boil it down to what

13
00:00:58,790 --> 00:00:59,960
‫they actually mean.

14
00:00:59,990 --> 00:01:10,010
‫A vector is simply a direction in 3D space, and it is a size or in mathematical parlance, a magnitude.

15
00:01:10,310 --> 00:01:16,880
‫Now this is all fine, but when it actually comes to representing this on a computer programmatically,

16
00:01:16,910 --> 00:01:18,110
‫it's even simpler.

17
00:01:18,110 --> 00:01:25,010
‫It's essentially just three floating point numbers an X, A, Y and Z component, and that perfectly

18
00:01:25,010 --> 00:01:28,010
‫represents a three dimensional vector.

19
00:01:28,010 --> 00:01:33,650
‫So let's have a little look at vectors in two dimensional space, because here I've got a two dimensional

20
00:01:33,650 --> 00:01:33,920
‫screen.

21
00:01:33,920 --> 00:01:36,020
‫It's easier for me to show you that.

22
00:01:36,200 --> 00:01:44,750
‫So imagine we have an X and Y components and we start off at the 00. being here in the top right for

23
00:01:44,750 --> 00:01:45,590
‫this example.

24
00:01:45,950 --> 00:01:50,600
‫And we want to position a character in this two dimensional space.

25
00:01:50,600 --> 00:01:58,610
‫Well, we can have a position vector that points to the location of the character and has a length that

26
00:01:58,610 --> 00:02:02,090
‫takes you from the 00. all the way to the character's location.

27
00:02:02,090 --> 00:02:05,330
‫And this can be broken down into its component parts.

28
00:02:05,330 --> 00:02:13,130
‫So you can have an X part and a Y part just like you might expect and how we were doing in our level

29
00:02:13,130 --> 00:02:13,670
‫in Unreal.

30
00:02:13,670 --> 00:02:18,920
‫Now what we can do is we can apply a movement vector to this position vector, so we can have another

31
00:02:18,920 --> 00:02:26,240
‫vector that has this direction and this magnitude or size, and we can actually add those two together

32
00:02:26,240 --> 00:02:29,810
‫to get us a new position like so.

33
00:02:29,810 --> 00:02:34,190
‫So this would look like this basically the position plus the move vector.

34
00:02:34,190 --> 00:02:39,260
‫So adding these two vectors together gives us a new position vector like so.

35
00:02:39,260 --> 00:02:44,810
‫And what's actually happening at a mathematical level is that we're simply to get the new positions.

36
00:02:44,810 --> 00:02:51,770
‫X We are adding together the X position of the original position, plus the X of the move and the same

37
00:02:51,770 --> 00:02:53,540
‫thing with the Y.

38
00:02:53,540 --> 00:02:58,260
‫So let's take a little bit more of a look at addition and subtraction with vectors.

39
00:02:58,340 --> 00:03:03,140
‫Essentially what we're saying is if we had a vector A that looks like this and a vector B that looks

40
00:03:03,140 --> 00:03:06,560
‫like this, then adding them together would give us the vector.

41
00:03:06,560 --> 00:03:13,880
‫Suppose we say that adding them together gives us a vector C, then vector C is simply the arrow that

42
00:03:13,880 --> 00:03:15,890
‫goes straight to the destination.

43
00:03:15,890 --> 00:03:21,830
‫Essentially you put these vectors head to tail like so it doesn't matter which order you do it in.

44
00:03:21,830 --> 00:03:24,020
‫By the way, you could put B first or a first.

45
00:03:24,050 --> 00:03:31,250
‫You're going to end up with the same location here, vector C, which just points straight to the final

46
00:03:31,250 --> 00:03:36,470
‫destinations like it's taking a shortcut and subtraction is incredibly similar.

47
00:03:36,470 --> 00:03:42,680
‫If you got vector A and vector B like this, then subtraction just involves taking a negative vector

48
00:03:42,680 --> 00:03:49,580
‫B, which is a vector that points in the opposite direction to the normal vector B, and then you can

49
00:03:49,580 --> 00:03:54,080
‫just go ahead and add them together as you would, which is going to end up looking a little bit like

50
00:03:54,080 --> 00:03:57,560
‫this where Vector C points to this location instead.

51
00:03:57,560 --> 00:04:03,920
‫Let's have a look at vector multiplication now, specifically multiplying a vector by a float.

52
00:04:03,950 --> 00:04:10,100
‫What happens if we take a and we say we want to multiply a by two to give us vector B?

53
00:04:10,340 --> 00:04:14,090
‫Well, in this case, it's actually fairly straightforward because all you got to do is think about

54
00:04:14,090 --> 00:04:19,460
‫adding together two vector A's that gives you a vector B that is twice as long.

55
00:04:19,460 --> 00:04:26,300
‫The size is twice the size of a vector A, and in fact, you don't have to be restricted to whole numbers

56
00:04:26,300 --> 00:04:26,660
‫here.

57
00:04:26,660 --> 00:04:30,350
‫You could have half a vector a is just going to be half as long.

58
00:04:30,350 --> 00:04:37,880
‫You could have 5.6 of a vector A which is going to be 5.6 times the length of that vector A, but the

59
00:04:37,880 --> 00:04:40,400
‫direction ultimately doesn't get changed.

60
00:04:40,400 --> 00:04:42,740
‫It will always have the same vector direction.

61
00:04:42,740 --> 00:04:46,490
‫So let me challenge you to a little treasure hunt here.

62
00:04:46,490 --> 00:04:49,550
‫I've defined an A, B and C vector.

63
00:04:49,550 --> 00:04:53,960
‫I've given you that visual representation with the arrow that is a size in a direction.

64
00:04:53,960 --> 00:05:00,260
‫I've also given you their numerical representations down below, and what I would like you to do is

65
00:05:00,260 --> 00:05:10,580
‫assuming we have our character here on our x y axis grid and we get given the cryptic treasure hunt

66
00:05:10,580 --> 00:05:19,670
‫directions given here, we've got a plus three times B minus C, that's where you will find the treasure.

67
00:05:19,670 --> 00:05:23,510
‫See if you can figure out where this character has got to move to.

68
00:05:23,820 --> 00:05:27,360
‫To find the treasure, pause the video and have a go.

69
00:05:31,690 --> 00:05:32,140
‫Okay.

70
00:05:32,140 --> 00:05:32,610
‫Welcome back.

71
00:05:32,620 --> 00:05:35,590
‫So first of all, A, we add A to it.

72
00:05:35,620 --> 00:05:40,660
‫We don't have to do any multiplication of it so we can add A and it's going to take us to this location

73
00:05:40,660 --> 00:05:41,530
‫over here.

74
00:05:41,530 --> 00:05:47,740
‫Then we are going to add B, but we're going to add it three times because it's multiplied by three

75
00:05:47,740 --> 00:05:52,810
‫and then we're going to subtract C so we're going to go in the negative direction or C or you can see

76
00:05:52,810 --> 00:05:57,730
‫I'm putting the arrow the other way round, so head to head instead of head to tail.

77
00:05:57,730 --> 00:06:01,210
‫And that effectively is the same thing as going in the opposite direction.

78
00:06:01,810 --> 00:06:08,470
‫And you can see we've ended up at this location here, which actually the resultant vector is this one

79
00:06:08,470 --> 00:06:08,980
‫here.

80
00:06:08,980 --> 00:06:12,340
‫That's the result of adding all those vectors together.

81
00:06:12,340 --> 00:06:18,010
‫So it's new, but it's new position, it's actual coordinate because we weren't at zero zero when we

82
00:06:18,010 --> 00:06:18,700
‫started.

83
00:06:18,700 --> 00:06:28,390
‫The actual coordinate is 51x5 and one on the y axis and the total resultant move vector is ten three.

84
00:06:28,390 --> 00:06:34,990
‫And you could verify this for yourself by actually adding together and multiplying appropriately the

85
00:06:34,990 --> 00:06:41,020
‫Xs and the Y's separately, and you just end up getting this movement vector defined here, which is

86
00:06:41,020 --> 00:06:43,540
‫that blue one showing up on the grid.

87
00:06:43,540 --> 00:06:49,720
‫So hopefully that's given you a little bit of a primer on adding vectors, subtracting them and multiplying

88
00:06:49,720 --> 00:06:50,080
‫them.

89
00:06:50,080 --> 00:06:51,040
‫In the next lecture.

90
00:06:51,040 --> 00:06:52,900
‫We will put this to use.

91
00:06:52,900 --> 00:06:53,740
‫I'll see you there.

