‫Hello and welcome.
‫In this lecture, we are going to be sorting out the angle of our blind space, hooking that up to our
‫gameplay.
‫And in the process we're going to have to learn a lot of maths, a lot of transforms and vectors.
‫So let's dive in and figure out how that works.
‫So we want to be able to get the angle at which we should be moving.
‫However, before we do that, we need to do a little bit of maths because we want to understand how
‫we can get this angle which is local to the player.
‫And I'll explain what I mean by local and global and how we can get that from a global velocity and
‫what those terms mean anyway.
‫So let's have a look.
‫First of all, we need to have a bit of a basic primer on transforms and what transforms are we've seen
‫them or you have seen them a little bit before.
‫When you look at any of the scene components, that's these ones in the hierarchy.
‫You can see they have a transform here.
‫So location, rotation, scale properties, that's basically what a transform is.
‫But one thing that you're not seeing here is that also part of this transform is the fact that these
‫same components are in a hierarchy, meaning that their transformer also has a parent or, you know,
‫basically hierarchical.
‫So how does that work?
‫Well, here's a kind of toy example.
‫We've got the cube here which say is our base, it's the center of our world or something.
‫So that's going to be our world space.
‫We've got this character here, the little smiley face, and he's got a position in the world relative
‫to his home base.
‫And then this character has a gun and the gun has a position relative to the character.
‫So the way this hierarchy works is that the parent of the gun is the character, the parent, or the
‫character is his home base or the world.
‫And then we have some local coordinate systems within these.
‫So the worlds coordinate system is the, the world system, the global system.
‫Then the coordinates of our character are then local to its position.
‫So the gun is positioned relative to its character.
‫What does that mean?
‫That means that if the character decides to go off on a little escapade, then the gun moves with it,
‫because the position of the gun relative to the character has remained the same, but because the character's
‫moved, its position in the world has moved.
‫Same happens with rotation.
‫If the character turns around, the gun must turn around as well.
‫That's how Transformers work essentially is also scaled, but we're not going to look at scale.
‫It's the same, but it's just complicating things and we don't need to do.
‫Have a look at that.
‫It's not relevant to us.
‫So let's have a look, a different look at this.
‫We've got global space and local space.
‫So the global space has the base at the center of the world and the character has gone off and to the
‫right.
‫The local space, on the other hand, sees things in the opposite light.
‫It says that the character is the center of the world and that the base has gone over to the left has
‫gone backwards.
‫You know, that's the difference between global and local.
‫It all depends on your point of view.
‫Everything is relative.
‫So this is what we mean when we talk about transforming between global and local space and which one
‫are we interested in?
‫For our angle, we're interested in a local angle relative to where the player is looking.
‫We're saying, you know, are we moving over to the right?
‫That's what we're saying that not globally, but locally.
‫Are we moving to the right locally to our player?
‫Because if our players turned around 180 degrees, he shouldn't play a left animation just because he
‫turned around.
‫So one more important distinction is how we do transformations for vectors of different sorts.
‫The first example I want to look at is a position vector.
‫So a position vector basically is a vector that gives us the difference between the current location
‫or the zero point in our coordinate system, which when we are focused on the character, is the character
‫himself, and then it gives us an arrow that points to where something should be.
‫So in this case, it is the gun location vector.
‫Now, if we transform this in to our world space, this is what happens.
‫The arrow now points from the center of our new world, the global space, and it points to the gun.
‫So that's what happens if you transform a position vector.
‫Now, if you do a direction vector, things look a little bit different.
‫A direction vector is one that says This is the way I should point, not necessarily where a thing is
‫and this transforms rather differently because we now aren't interested in it pointing to the same location.
‫So that position doesn't really get updated.
‫Instead it get the a vector gets rotated and scaled or whatever it is and we end up with it looking
‫a little bit like this.
‫So that's actually the kind of transforming.
‫Nation that we want to be doing because we're dealing with a velocity which is a direction vector rather
‫than a position vector or velocity doesn't tell us anything about where we should be.
‫It tells us about what direction we should be going in and how fast we should be going in that direction.
‫So with that theory out of the way, let's go ahead and calculate our direction from this velocity.
‫So we know that velocity is in global space and we want to convert it to local space.
‫Now that means that generally speaking, we're always trying to do things the other way round, usually
‫because we're saying, well, we've got the position, the local position of a gun, it's local transform.
‫We want to figure out what it is in world space so that we can render it relative to everything else.
‫Now, that's not what we're trying to do here.
‫We're trying to do the opposite.
‫So what we actually want is called an inverse transform.
‫The transform goes this way from local to global.
‫The inverse transform goes from global to local.
‫So because we've got this global velocity, we want to inverse transform.
‫So let's take off here and look for inverse transform.
‫And you can see that we've got these two options.
‫We don't care about these matrix ones.
‫We've got the two options of for direction and location.
‫And as I said, the difference is that a location will move that position around.
‫The direction is just going to apply the rotation and scale.
‫So we want the direction.
‫We need a transform to rotate it by.
‫We're going to have to get that transform of the pawn itself, of the character.
‫Where is that -- in the world.
‫So let's go ahead and grab off the -- owner and look for the transform.
‫Property get actor transform.
‫That would be the one.
‫We'll pipe that in to our inverse transform direction and we've got ourselves a new vector out of this.
‫So the next step would be to get the rotation of this vector.
‫So we'll look going to look for rotation.
‫See what we can find.
‫We've got find look rotation, make rotation from axes to cotangent.
‫Now, let's have a look at rotation from X vector.
‫If you read the documentation here it says it's going to set the your and pitch from this vector but
‫it won't set the role because it can't get that information from a vector.
‫That's fine.
‫We don't care about the role in this case.
‫All we care about is the user because we want to see how far we're turning to the right or left.
‫So rotation from X vector, that's the one that we want is going to return us a rotator.
‫And for us to get just the user from that rotator, we're going to right click on the pin and hit split
‫struct pin, which goes ahead and splits that struct into the roll pitch.
‫And your you could do that on a vector as well.
‫By the way, I think you can right click and let's see, I think I'd have to break the link to do it.
‫So I'm not going to show you.
‫But basically we've now got a user here and that's what we want to set.
‫So again, many challenge set up the user to be the angle and test it out.
‫So again, mini challenge set up the year to be an annual variable that goes into the blend space and
‫test it out, try it out in the game and see if you're able to run around successfully.
‫Okay.
‫Welcome back.
‫So we're going to drag in again angle, variable set angle, going to set the angle from the yaw and
‫we're going to get the execution pin from the end of speed.
‫I'm going to compile and save that and we're going to go over to the sandbox and hit play.
‫And now let's try moving around.
‫A controller would be ideal so you can test out the different gradients and the nuances.
‫And sure enough, you can see if I start moving around now, I'm able to move backwards, I'm able to
‫move forward, sprinting and sideways and 45 degrees.
‫All of that works based on the maths that we've calculated to calculate our angle.
‫Great stuff.
‫So we've learned a lot about transforms and vectors and how you can transform vectors, both inverse
‫and forward transforming.
‫And in the next lecture, we're going to look at fixing this foot sliding that we are seeing here.
‫I'll see you there.