‫Hello and welcome.
‫In this lecture, we're going to be trying to understand a little bit more about these vector structs
‫and the mathematics that underpins them, so that by the end of this lecture you will feel comfortable
‫adding and subtracting vectors as well as multiplying them by floating point values.
‫Let's dive in.
‫So soon, we're going to want to start setting our impulse in the correct rotated direction.
‫But before we do that, we need to understand a little bit more about the mathematics that underlies
‫vectors.
‫Now, in this video, I'm going to be giving you a whistle stop tour of vector mathematics.
‫But if you want some more in-depth explanations, then we have a whole course on maths for game development,
‫which I would highly recommend.
‫Vectors are essentially a mathematical concept and they're quite simple when you boil it down to what
‫they actually mean.
‫A vector is simply a direction in 3D space, and it is a size or in mathematical parlance, a magnitude.
‫Now this is all fine, but when it actually comes to representing this on a computer programmatically,
‫it's even simpler.
‫It's essentially just three floating point numbers an X, A, Y and Z component, and that perfectly
‫represents a three dimensional vector.
‫So let's have a little look at vectors in two dimensional space, because here I've got a two dimensional
‫screen.
‫It's easier for me to show you that.
‫So imagine we have an X and Y components and we start off at the 00. being here in the top right for
‫this example.
‫And we want to position a character in this two dimensional space.
‫Well, we can have a position vector that points to the location of the character and has a length that
‫takes you from the 00. all the way to the character's location.
‫And this can be broken down into its component parts.
‫So you can have an X part and a Y part just like you might expect and how we were doing in our level
‫in Unreal.
‫Now what we can do is we can apply a movement vector to this position vector, so we can have another
‫vector that has this direction and this magnitude or size, and we can actually add those two together
‫to get us a new position like so.
‫So this would look like this basically the position plus the move vector.
‫So adding these two vectors together gives us a new position vector like so.
‫And what's actually happening at a mathematical level is that we're simply to get the new positions.
‫X We are adding together the X position of the original position, plus the X of the move and the same
‫thing with the Y.
‫So let's take a little bit more of a look at addition and subtraction with vectors.
‫Essentially what we're saying is if we had a vector A that looks like this and a vector B that looks
‫like this, then adding them together would give us the vector.
‫Suppose we say that adding them together gives us a vector C, then vector C is simply the arrow that
‫goes straight to the destination.
‫Essentially you put these vectors head to tail like so it doesn't matter which order you do it in.
‫By the way, you could put B first or a first.
‫You're going to end up with the same location here, vector C, which just points straight to the final
‫destinations like it's taking a shortcut and subtraction is incredibly similar.
‫If you got vector A and vector B like this, then subtraction just involves taking a negative vector
‫B, which is a vector that points in the opposite direction to the normal vector B, and then you can
‫just go ahead and add them together as you would, which is going to end up looking a little bit like
‫this where Vector C points to this location instead.
‫Let's have a look at vector multiplication now, specifically multiplying a vector by a float.
‫What happens if we take a and we say we want to multiply a by two to give us vector B?
‫Well, in this case, it's actually fairly straightforward because all you got to do is think about
‫adding together two vector A's that gives you a vector B that is twice as long.
‫The size is twice the size of a vector A, and in fact, you don't have to be restricted to whole numbers
‫here.
‫You could have half a vector a is just going to be half as long.
‫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
‫direction ultimately doesn't get changed.
‫It will always have the same vector direction.
‫So let me challenge you to a little treasure hunt here.
‫I've defined an A, B and C vector.
‫I've given you that visual representation with the arrow that is a size in a direction.
‫I've also given you their numerical representations down below, and what I would like you to do is
‫assuming we have our character here on our x y axis grid and we get given the cryptic treasure hunt
‫directions given here, we've got a plus three times B minus C, that's where you will find the treasure.
‫See if you can figure out where this character has got to move to.
‫To find the treasure, pause the video and have a go.
‫Okay.
‫Welcome back.
‫So first of all, A, we add A to it.
‫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
‫over here.
‫Then we are going to add B, but we're going to add it three times because it's multiplied by three
‫and then we're going to subtract C so we're going to go in the negative direction or C or you can see
‫I'm putting the arrow the other way round, so head to head instead of head to tail.
‫And that effectively is the same thing as going in the opposite direction.
‫And you can see we've ended up at this location here, which actually the resultant vector is this one
‫here.
‫That's the result of adding all those vectors together.
‫So it's new, but it's new position, it's actual coordinate because we weren't at zero zero when we
‫started.
‫The actual coordinate is 51x5 and one on the y axis and the total resultant move vector is ten three.
‫And you could verify this for yourself by actually adding together and multiplying appropriately the
‫Xs and the Y's separately, and you just end up getting this movement vector defined here, which is
‫that blue one showing up on the grid.
‫So hopefully that's given you a little bit of a primer on adding vectors, subtracting them and multiplying
‫them.
‫In the next lecture.
‫We will put this to use.
‫I'll see you there.