‫Hello and welcome.
‫This lecture we are going to be filling out our animation state machine so that there are more states
‫here allowing us to have a animation that jumps us into that initial jump state.
‫As you can see, there's a little bit more spring to my jump and we are going to learn about such things
‫as automatic transitions and how to nest one state machine within another, which is what we're going
‫to do for ad death animation.
‫Now let's dive in and see how it works.
‫So as promised in the last lecture, we're going to hook up our is airborne variable to the gameplay.
‫Now the way we're going to do this is to get from the pawn or particularly from our shooter character.
‫We want to find out essentially whether the character is airborne.
‫And I find that the only way you can do this is essentially through the character movement component.
‫So let me show you what I mean.
‫If we go to our cast node that is casting to the shooter character, then we can drag off of this.
‫In fact, what we can do is a more general cast in this particular instance because we don't need the
‫specific information associated with is dead.
‫So what I'm going to do here is we'll take this pin, the pawn owner, and we're going to do a cast
‫to a character in this case, because all we need to know is that this is a character instance.
‫Then we're going to add a new execution pin up at the sequence node, drag that down to our cast to
‫character, and then from the character will drag off of its character pin.
‫And we're going to look for basically something along the line of airborne nothing there maybe jump
‫seems to be more interesting it's saying is jump providing force can jump jump all that sort of stuff.
‫We got something there, but that's not quite it.
‫How about if we look for falling?
‫There you go.
‫We've got an is falling.
‫And if you click that, you can see that it automatically gets hold of the character movement component
‫from that character to see whether we are falling or not.
‫Then what we can do is we can pass that in to set the value of is airborne and obviously we're only
‫going to be setting this if our cast to character succeeds.
‫So let's hook in that execution pin right there.
‫You can go ahead and compile that.
‫Obviously, it's not going to change the preview, so we've got to go and try and play it.
‫So let's play we jump and you can see we've got this falling variable instantly being true and that
‫is working quite nicely actually.
‫We were able to jump and land and jump and land and kill our enemies, obviously.
‫So now I'd like to add a little bit more complication to our anim graph.
‫So in the locomotion state machine at the moment, we've got two states here.
‫But what I'd really like to do is to play a jumping animation, then an animation where we're airborne
‫and then a landing animation when we hit the ground.
‫To do that, we need some more states in our state machine.
‫So let's go ahead.
‫I'm going to do one of the set of states and you can do the final one.
‫So the first one is going to be our jumping state.
‫And that is going to play an animation that gets us off the ground.
‫So let's go into the jumping state and to the output animation pose.
‫We're going to link a new animation.
‫We'll look for jump.
‫We're looking for all the ones sub fixed with combat.
‫So we're going to look for jump start combat.
‫There you go.
‫And that's what we want.
‫Then we're going to go back to our locomotion state machine and we want to hook up some transitions.
‫So we're going to transition from grounded to jumping.
‫That's going to happen if we're airborne.
‫So put in the air is airborne in there.
‫Unfortunately, there's no way that I could see of changing the transition.
‫So we're just going to have to delete the old transitions here in both cases.
‫Then we're going to need a transition from jumping to is airborne, but we don't have a variable or
‫state for that.
‫So when is it that we're going to transition from jumping to his airborne?
‫Well, we want to do it when the jumping animation has finished.
‫When we've finished jumping, if you go and have a look at the jumping animation, you can see that
‫it involves him lifting his feet off the ground like this.
‫And so we want to basically transition into our apex animation when it's finished.
‫Fortunately, there's an option for that in the transitions.
‫If you select the transition rather than going into it, you can look at its details pane.
‫And there's one option here.
‫Which I expand out, says automatic rule based on sequence player in state.
‫If you check that, basically what it's going to do is when we've nearly finished jumping, it's going
‫to start transitioning into the next animation and you can actually control when that transition is
‫and how long that crossfade is.
‫Here in the blend settings, you can see the duration of the blend is about 0.2, but seeing as these
‫two transitioning into each other particularly well, I'm going to make that 0.01.
‫So I'm going to make that really short transition.
‫So let's see what that looks like.
‫So we're going to go into is airborne.
‫It plays that jumping animation and then goes straight into the airborne state.
‫Once the animation is finished.
‫Let's try that one more time and we can try it one more time.
‫That is the problem because we've got no transition out of the airborne state back to grounded and that
‫is indeed going to be your challenge.
‫So what you're going to do is add a landing state which is going to play a landing animation.
‫So add the new state, add the animation that's most appropriate for landing.
‫In your opinion, you might want to look for things with the jump prefix and the combat suffix.
‫Then you're going to transition from airborne on a boolean into this landing state.
‫And then from that landing state, you're going to transition to grounded when the landing animation
‫has finished.
‫Play it, play around, see how it feels.
‫Does it feel good?
‫Does it look right?
‫And you may want to look at tweaking those transition times to see if that makes things feel better.
‫Pause the video and have a go at playing around with our state machine.
‫Okay.
‫Welcome back.
‫So let's give this a shot.
‫We're going to add a new state in here.
‫It's going to be called landing.
‫And in this landing state, if we go in, we need an animation for it.
‫I'm going to search for jump and what we want is jump land combat like so and then we can go back up
‫to our locomotion state machine.
‫We need a transition from airborne to landing.
‫Let's double click on that.
‫And this needs to be the not in not airborne basically so not node then the is airborne passed into
‫that.
‫So that's our transition condition.
‫So when we're at the apex, once the not is airborne is unchecked, then we go into our landing state.
‫Then from our landing state, we want to transition to grounded when finished.
‫So if you click on the transition and check the automatic rule checkbox, it's going to do that when
‫it's finished.
‫So let's try that out.
‫We're going to go into his airborne.
‫It plays jumping, it goes into Airborne and then uncheck it.
‫It goes to landing and back out.
‫Let's do that again.
‫Seems pretty good.
‫Okay.
‫So what we're going to do now is try playing it, jumping around and landing.
‫Okay.
‫This is feeling quite good.
‫There's a little bit of lag when I'm landing between me landing and the running animation being played.
‫So I'm going to click on the transition from landing to Grounded and have a look at our landing blend
‫settings.
‫Now we've got this duration of 0.1.
‫That's how long it's taking us to do the transition and what's going on.
‫So in our landing combat animation, how long is that landing?
‫Combat animation?
‫If I pause it, scroll along here.
‫You can see that it is about 0.2.
‫So it's actually taking the whole of that time and transitioning during that time in to our grounded
‫locomotion.
‫So that's kind of what we want because as soon as we've landed on the ground, as soon as the gameplay
‫is telling us we've landed on the ground, we want to start showing some foot movement because otherwise
‫it's going to look a little bit weird.
‫So we want that transition to actually start happening as soon as possible, which is why we're playing
‫very little of the landing animation and transitioning into the grounded one as much as quickly as possible.
‫The only thing that we can really tweak here is the transition mode, which kind of dictates the shape
‫of that curve as a shape of how much landing versus grounded we have over time.
‫And you can test out various of these options, see which ones feel best for you.
‫For me, it's the exponential out that feels best because that shows as much grounded as possible as
‫early as possible, but without it feeling jarring.
‫So if we now do is airborne and then go back to ground, you can see that it feels like it's going into
‫grounded pretty quickly, which is what we want.
‫So I'm going to go ahead and hit play and see if that feels better.
‫Yeah, it feels a bit more responsive to me hitting the ground, which is exactly what I want.
‫Now, in practice, if you had more animations here to work with, what you might want to do with the
‫landed state is to have a blend space there and have a recovery animation.
‫So depending how hard you hit the ground, you might hit you might play a recovery animation, which
‫is blended depending on which direction you're moving in.
‫So he would land with a hefty thud, but kind of stagger over to the left, for example.
‫Now, that is not something that we're going to cover here just because we don't have the animations.
‫But in theory, that's what you might do.
‫So now one final kind of mini challenge for you is that we've currently got this blend poses by bool
‫going on for our death animation.
‫This could be done with a new state machine for death.
‫See if you could try and refactor this anim graph so that it works with a state machine for death instead
‫of this blend poses by bool.
‫So hopefully you took me up on that challenge.
‫What we're going to do is we're going to right click do a new state machine entirely new.
‫We're going to rename this state machine to death or something similar like so then I'm going to go
‫into that state machine and we're going to add two states.
‫One is going to be the state alive and the other state is going to be dead.
‫And then we're going to add some transitions.
‫So transition from alive to dead, that is going to happen.
‫If we double click, it's going to happen when is dead is true like so.
‫And then we want a maybe we want a transition back to alive and we can just have that for testing purposes
‫at least that's going to have a not boolean and it's going to have is dead so basically is not dead.
‫We're going to go back the other way.
‫We want to default to being in the alive state.
‫That makes sense.
‫And then we need some animations to play.
‫So for Dead, we've already got that death animation.
‫So I'm going to go in back up to the anim graph to cut that out, go back into the dead state and paste
‫that death animation in here.
‫Then in our live state.
‫What do we want to play there?
‫Well, actually, we want to play everything else.
‫We want to play the aim of sets.
‫We want to play the locomotion.
‫So I'm going to cut all of that.
‫And this is where it gets interesting.
‫Now we've got a state machine running within a state machine, which is entirely possible.
‫So we can then pipe in this aim of set into our output for the alive state and go back up to our anim
‫graph entirely, remove all the nodes here and just pipe our death state machine into our output.
‫And this works because we've got two top level states.
‫Basically, we're saying they're either alive or dead.
‫If you're dead, you just play a death animation.
‫If you're alive, however, you do this aim offset and you do your locomotion state machine, which
‫in turn has its own set of states.
‫So it's layering state machine on top of state machine.
‫Hopefully you see how that can be really powerful.
‫So we can do now is dead, which overrides everything else that's running.
‫It's no longer running the locomotion state machine because we're just playing that death animation.
‫If I die as we go back to running the animation for a live but we can replay our death crucially, which
‫previously we couldn't do.
‫And that's because when you leave a state in an animation state machine, it resets the animation within
‫it, it resets it to the beginning.
‫So that's a really useful feature here for death.
‫So to recap, what we've learnt about in this lecture is how to make more complex state machines and
‫state machines within each other.
‫And we've seen about automatic transitions and how they can help us make a sequence of transitions happen
‫more easily.
‫And I'll see you in the next lecture.