‫Hello and welcome to this lecture.
‫We're going to be playing with AIM offsets that will allow our mesh to move its arms up and down.
‫As we aim up and down, let's dive in and see what that's all about.
‫So at the moment, if we aim up and down, you can see that our characters arms aren't actually doing
‫anything and the gun is not really looking like it should be pointing up and firing and hitting the
‫location that we're actually hitting.
‫So how do we go about changing this?
‫Well, it's a change to our animation blueprint.
‫So let's go ahead and open up the animation blueprint as a starting point and dock it to our main window.
‫And then I want to introduce you to a new type of animation asset that we haven't seen before.
‫We've seen blend spaces, we've seen animations.
‫The next thing that I want to show you is something called an animation offset and particularly an aim
‫offset.
‫So if we look for the keyword ayo in our animations, we're looking for these ones with a little blue
‫underline called aim offsets.
‫And there's a couple of them.
‫The one I'm interested in is AoE combat, which should be around here somewhere.
‫They would go a idle A0 combat.
‫If you go and select that, then you'll see that we've got something looking a lot like our blend space.
‫Except this time if you move the little green nubbin, what's going on is it's changing the direction
‫that our characters mesh is pointing.
‫So if we come over to the left, he points his gun to the left, we come over to the right, he points
‫his gun to the right.
‫And similarly with up and down, if you go pitch up, then he looks all the way up.
‫He pitched down, he looks all the way down and tries to shoot down.
‫Now the difference with this and other animations that we've seen is that this is known as an additive
‫animation.
‫If you go to the details pane, you can see that it's additive because it says additive settings and
‫there's this animation based pose that it's basing all of this off.
‫Basically what it means when it's additive is that this animation can be added on top of your other
‫animations.
‫So it's saying, I can do this aiming while you're running.
‫I can add the information about where my arms have moved relative to your run pose and add them on top.
‫So how does this look?
‫If we go to our animation blueprint, what we want to do is add this information after we've added all
‫this information about locomotion and probably not before death, because death should be the final
‫thing.
‫So we want to have the locomotion.
‫So we've got all our running animation in there.
‫We want to add on top of that the a little bit of information about where our arms should be moved so
‫that we're aiming correctly.
‫So to do this, we can right click and add in our aim offset.
‫We can do it from the asset browser as well.
‫I'm going to look for A0 and then as I said, we're looking for that combat version, which is a different
‫place in this browser.
‫Funnily enough, if I track that in, then what you get is something with an input pin which says What's
‫the base powered?
‫Notice that locomotion blend space didn't have an input pin because it's supplying you the whole animation,
‫whereas this aim offset because it's an additive animation, it requires something to add on top of.
‫So you need to give it a base pose which is going to come from our locomotion, and then we're going
‫to go and input that into our false pose of the blend, whether we are dead or not, because we're only
‫showing this if we're not dead.
‫And then I want to show you that if I were to change the pitch to one or maybe to 180, actually, and
‫go ahead and compile, then you can see that he's fully looking upwards.
‫Now, another tweak I want to do here is in the event graph.
‫At the moment, we've got a rather vexing situation where we can't tweak anything in the anim preview
‫because it's being overwritten with zeros by our event graph.
‫An easy way to fix this is to simply put a check in here for whether the pawn owner that we've got here
‫is valid, namely is it null?
‫So if we put an is valid here and the one with the question mark automatically gives us these execution
‫nodes and if we pass through our update animation execution node and only set things if that's valid,
‫then what's going to happen is that when you are not actually playing and there isn't a pawn there to
‫give us the information, it's going to allow us to set it in.
‫The Anim Preview Editor.
‫So now I can change the speed and you can see that he starts running with his aim offset set up high.
‫So let's set this so that our pitch is actually a variable here.
‫So I'm going to right click on pitch and promote the variable and bring that variable down here where
‫it's visible and change its name to pitch.
‫Or in fact, let's be more specific, this is the aim pitch like.
‫So now if we go ahead and compile, we set a default aim pitch by accident.
‫We want to set that down to zero by default.
‫I'm going to go ahead and compile that.
‫And now if we go ahead and change the speed and then change the aim pitch.
‫You can see we can aim up and we can aim down, which is exactly what we want.
‫Now, the problem here is it's not being set in our game just yet.
‫If we go up and down, none of that is coming from information from our control rotation and our aiming.
‫So we need to go back to our event graph and get some of that information in here.
‫Now, I'm just going to space things out a little bit here because this is getting rather long.
‫And what I want to do is off this valid pin is I want to put a sequence node which is going to let me
‫spread things out a little bit down the in the vertical direction as well.
‫So the sequence node, first of all, is going to go off to setting the speed and angle over here.
‫Then I think we can move this stuff to do with casting to the shooter character.
‫I think we can bring this down further vertically, hooking up that sequence pin and the object pin
‫to our try get pawn owner node, then we can add another pin into the sequence.
‫And this time I want to get two pieces of information from our pawn owner.
‫The first one is going to be our control rotation.
‫So let's do a get control rotation.
‫But this isn't going to be enough because our control rotation, if we split the pin, you can see we've
‫got a pitch in here and we could try setting that pitch.
‫Let's let's give that a go.
‫So if I do a set pitch and connect up the execution node to the execution node from our sequence, adding
‫in a bit of a redirect to there, what's going to happen if we compile, save, hit play and then aim
‫up works fine.
‫Aim down does not turn around.
‫Then things start to look even more weird.
‫Now what's going on there is that this control rotation is entirely global and so doesn't take into
‫account the direction that our player is already facing.
‫So to take that into account, we need to go to the pawn again and get the actor rotation.
‫And then what we want to find is the rotation between the actor's rotation to the control rotation.
‫And the way we do this is I'm just going to disconnect the AM pitch.
‫Break that link and right click and recombine the struct pins is I want to do a delta between those
‫two so I can take off of the control rotation and look for Delta.
‫And Delta is basically a fancy way of saying subtraction between rotators.
‫So what we want to do is take our control rotation and subtract the base rotation, which is going to
‫be our actor rotation.
‫So that's B so it's going to be A minus B if you hover over, that's what the Delta rotator does.
‫And we basically want to be saying, Yeah, I want the control rotation, but take away all that information
‫about our active rotation.
‫So I can just know whether we're aiming up and down relative to the direction that our character is
‫facing.
‫And then if I split out the return value pin from that and use the pitch from there, we're going to
‫see that everything works as expected.
‫When I look up my naming up, when I look down, I'm aiming down and doesn't matter which way I'm facing
‫in the world, that's always going to be the case.
‫So that's almost it for our aim rotation.
‫The only problem is that at the moment our eye is incapable of aiming like this.
‫So if I go and put a shooter character up on the stairs over here and then we go over to try and hound
‫him down, try and get him to come over to us.
‫Here he comes.
‫You can see that he's just shooting off into the wall.
‫He's not trying to aim at all, which is a bit sad.
‫So what's going on there?
‫If we go to our eye and our behavior tree, you can see that we're setting a default focus to a location.
‫And by default, if you set a focus to a location, then Unreal is not going to update your control
‫rotation in the same way it's not going to do the pitch.
‫So that's a bit sad.
‫Okay, so what we need to do is go to a blackboard and change this player location to just be a reference
‫to the player instead.
‫Then we need to change this vector over to be an object.
‫So now what we've got is a blackboard key for the player, which is an object, and we can change the
‫base class to b actor if we want to, although it's not particularly important.
‫And then what that means is over in the behavior tree, we can switch things up so that we are moving
‫to instead of moving to our player location, we're moving to the player actor.
‫We can set the focus to be the player actor and update the player.
‫Location of scene now needs to be pointing to a player actor as well.
‫Now, this isn't going to work just yet because our update player location of scene is currently trying
‫to set a location into this key.
‫So a little mini challenge for you, see if you can update it.
‫So instead of setting the location in that behavior tree service, we're setting the actual actor pause
‫video and have a go.
‫Okay, welcome back.
‫So we're going to go over in to Visual Studio code and look for our service particularly.
‫It's the service underscore player location if seen.
‫And we're going to change this to instead of set value as vector, it's going to be set value as object,
‫simple as that.
‫We had the choices of types in the blackboard, and that's what we're going to tell it here.
‫Now, obviously, it's going to complain that what we're trying to set is a vector rather than an object.
‫So we're going to just remove the get actor location and pass in the player pawn.
‫Instead, clearing the value is the same as it was before, so we can just go back into the editor,
‫hit, compile, and see if this new set up is working with aiming for the I Kate let's dive in hit play.
‫Go and find out I up on the stairs.
‫Get them to try and come and look down as come on I and one more thing that I've forgotten from the
‫behaviour tree to update is the cansee player at the moment is has gone on reset the blackboard key
‫to self actor we want to that to be player basically is the player set let's go and make that change
‫because at the moment the I wasn't coming to chase us now it's chasing us and in fact if you jump,
‫you can just about see that the aim rotation of this guy is changing.
‫Let's go over to the stairs and see whether he can shoot down from the stairs at us.
‫Excellent.
‫He's changed his rotation and indeed he is shooting right at us.
‫Both of them are where?
‫So I'm losing health and will soon die.
‫Okay, that's it for this lecture we have added in an aim offset and we have updated our eye so that
‫it can use that to aim as well.
‫The next lecture we're going to be doing something about this funny running while in the air.
‫I will see you there.