‫Hello and welcome.
‫In this lecture, we are going to be learning how to connect up our animations to our gameplay and we're
‫going to get the speed of our character hooked up to the blend space so that we can get this effect.
‫Let's dive in and see how it's done.
‫Okay.
‫So we have got ourselves a blend space to integrate in to this AVP shooter character.
‫First thing I'm going to do is I'm going to go ahead and delete these two blends that we use as an example
‫of how the animation blueprint anim graph works.
‫And instead we're going to bring in from the asset browser in the bottom right, the blend space.
‫So we've just created this BBS underscore locomotion.
‫If you drag that in to your anim graph, you'll see it brings in this little green node here.
‫And very much like the other blend nodes and things like that, we've got ourselves and an impose that
‫we can drag into our output.
‫And if I hit compile, you can see it's just in our default space and then you can see this little visualization
‫which is quite handy of the little blend space and we could go ahead and change the values in here statically
‫or we could input some variables into here.
‫Well, we're probably going to want to do the latter, so I'm going to go ahead and delete the two variables
‫we've got the left and the forward, because we know now that what we want is an angle which is going
‫to be a float.
‫So let's change that over to float and we're going to need a speed variable as well, which is also
‫a float.
‫And we can patch those two in the speed variable into the speed and the angle into the angle.
‫And we'll go hit compile, look at our animate preview editor and just tweak the values.
‫So first of all, the speed let's bring the speed up a little bit.
‫Let's bring the speed up to about 30.
‫See what happens.
‫They go.
‫He starts to walk by, bring it up to 70.
‫He is getting closer to running.
‫I bring it to 100.
‫Well, not ten, 100.
‫Then he's full on running and then we can change the angle.
‫So at 90 degrees he's going 90 to the right, -90 is going mind going over to the left.
‫We can go somewhere in between.
‫So you can say 45 degrees.
‫You can see he runs at a 45 degree angle and you can see the blend space where it is trying to pick
‫in the blend space and what animations.
‫It's sort of blending between it's blending between that forward animation and that 90 degrees right
‫animation.
‫So that's cool.
‫We've got that going.
‫But as we know, this needs to be driven by our actual gameplay and why do we do that anyway?
‫Why don't we just have the animations drive our gameplay saying, you know, we need to be moving forward
‫at such and such a pace?
‫Well, the reason for not doing that, the reason for not using the animation to drive gameplay is that
‫you often want your designer to be able to tweak all sorts of variables about your gameplay.
‫You want them to be able to say, Okay, well, it doesn't feel right that this character is running
‫at this speed.
‫He needs to be running at this speed instead.
‫And walking should be more at this speed.
‫So you don't want your animations to constrain the design and game feel.
‫You want the animations to come off the back of your game feel and make it look good.
‫So during your design process, you might realize, actually we need a faster running animation and
‫that's okay, but you want to be able to change up the game first to get there, rather than have to
‫go and try and record a different running animation or find a different running animation and then realize
‫that actually that didn't improve the feel of the game.
‫That's why I want to keep these two things as separate as possible.
‫There are times when things really must line up with the animations, but this is not one of them.
‫So there are exceptions to every rule.
‫So don't take this as a completely set in stone rule.
‫You'll definitely see instances of games that drive some features from the animation, but generally
‫speaking, we want to do it the other way around.
‫We want to say, what's the speed of the character in the game?
‫Let me go and update the speed of the animation rather than saying, What's the speed of the animation?
‫Let me update the speed of the character in the game.
‫Okay.
‫With that said, how do we do this?
‫Basically, the mechanics of it are that this blueprint, this animation blueprint, has an event graph
‫like other blueprints do, which means that it can have things like a TIC event.
‫If I go over in to the event graph and have a look, we have got a couple of event nodes in here that
‫we can use to start from.
‫We've got this blueprint update animation.
‫If we come off of this every time it wants to update the animation, it's going to give us the execution
‫node and allow us to go ahead and grab some state.
‫So what we're going to do is every time this is called, we go and grab some state and notice here it's
‫got this get spawn owner that's saying go ahead and get the pawn object.
‫So let's remind ourselves the -- in this case is a character, character being a subclass of --
‫and it would be this beep shooter character.
‫Why would it be the beep shooter character?
‫Well, let's see.
‫Because this character, if we select the mesh, go to the viewport.
‫It's currently running just a simple animation, but what we want to do is change the animation mode
‫over to use animation blueprints and we want to use that app shooter character.
‫So that is why this is the -- owner.
‫It's using that animation blueprint.
‫So the blueprint now has a pawn owner.
‫And so what we want to do in this update function, just to summarize, is we want to grab the information
‫from the pawn about its movement.
‫We want to say, what's your speed?
‫What's the angle of your movement?
‫That's what we're going to calculate in this lecture.
‫We're just going to do the speed because it's the simplest to do.
‫The angle is going to require a little bit of manipulation with transforms, which we're going to look
‫at in the next lecture.
‫So the node that we're going to want here is to get the velocity of our pawn owner that gives us this
‫vector here.
‫And then off the back of that vector, we want to find its magnitude or its length so we can drag off
‫of that vector search for the magnitude.
‫And notice it's been clever here and I've searched for magnitude, but it's given me the function called
‫vector length.
‫So clearly magnitude they've clocked that it's a synonym for vector length.
‫Why do we want to get the vector length rather than the vector itself?
‫Because we're looking for a float, which is the speed vectors include the direction as well as the
‫speed, which we're going to need to calculate the angle.
‫But it isn't what we need to calculate the speed.
‫So a little mini challenge for you here.
‫Go ahead.
‫There there isn't any other challenge in this lecture.
‫Go ahead and set the speed using this vector length.
‫And remember if you need any execution pin.
‫We're trying to do this on the blueprint update animation.
‫So pause the video and have a go.
‫Okay, welcome back.
‫So the speed is what we want to set.
‫So if I drag that in to the blueprint and hit set speed, you can see we've got an execution pin that
‫we need.
‫We're going to get that from the Blueprint Update animation and we need the data pin, which is going
‫to be the speed that comes from our vector length of getting our velocity.
‫So it should be able to go ahead and save and compile that.
‫You can see that's reset the speed to zero because now it's trying to set it from a pawn owner that
‫is not really there.
‫So what we're going to want to do is actually go ahead and play in the world and see what we've got.
‫Okay, this is much better.
‫We've got ourselves a pawn that's staying static on the ground, except for when I move, at which point
‫it is giving me some speed.
‫And if you use an analog input such as a controller, you can see that by changing the analog input
‫that sort of changes the speed.
‫We can change how fast this guy is moving.
‫Now, obviously, there are two problems here.
‫The first one being that if I move off an angle, it's just using the absolute speed.
‫So it's not adjusting that angle in our blend space.
‫And so the animation looks wrong.
‫The other problem is that we're getting definitely some foot sliding here because the speed of our animation
‫is not matching the speed of the character in our game.
‫That's something that we will look at fixing in a following lecture as well.
‫Great stuff.
‫Hopefully you now understand how animations should hook up to gameplay using the animation blueprint
‫and you should be able to go and apply that to your own game.
‫See you in the next lecture where we will be hooking up those angles so that this movement looks a bit
‫more natural.