Hi everyone and welcome back to the third person camera
tutorials and Unity. This is going to be the
last lesson of the series. And in this lesson,
we're gonna be working on getting just nicer sense of
animations going, we want to have a walk animation,
a jog animation and run animation. I wanna
be able to tween between those. So what we're
gonna do for this is we're gonna build up and
this is just a single blend tree right now we're going
to add some functionality to it to make it have
several blend trees and blend between those. So in order
to do that we need to set this locomotion blend tree.
We need to start giving it new fields.
We're gonna give it several new fields that are all
blend trees as well. So the idea here is
we're kind of just blending between blend trees if that makes
sense. So we're going to go ahead and remove
all of our animations. Sounds kind of scary but
it's not really too bad. So remove all these
at a new blend tree and several of these actually
and that should be good. So we'll make this
one are walking blend tree yeah, it's we're gonna
make this one the run blend tree or jog actually,
this one will be the run. Mhm And
finally we'll have sprints. Okay, we want to
do now is we want to give animations to all
these trees and we want to give them a parameter.
So they all need to be what's going to
determine this is going to be a speed and then
direction is going to determine which one of these gets
called. So I want to set thresholds for each
one of these at a separate speed. So walk
is good at zero, Jog is going to be
set 0.6. Run is going to be set to 0.8.
and sprint will be too so this is how we're
gonna uh transition between these. So let's go ahead
and give that a preview. Mhm Looks like we
need to click on our character. There's no animations
That makes sense. Okay, so we need
to add animations for all these real fast. Such
a sad motion fields to everything. 24 Walk animations
for these. We're gonna use ex organized several more
than that. We want to go into our animations
folder, go to the walk animations and we're going
to use all of these. So I want to
walk to be one of those and I want to
have a walk left medium and I walk short medium
to the left and finally walk left wide. Where
did the same thing for the positive values which are
going to be our walk right short. Yeah.
Walk right medium and walk right wide. Modernize the
timescales and set the thresholds by hand. You want
to set these two various direction values. You want
to do negative 1 to 1. So we're new
negative one negative. That's a time scale. It's
marginalize those. Again, I want to use negative
.6 for this one. Negative 0.3 zero 0.3.6
& one. So it's gonna be our walk into
mission. Mhm. And if you just have the
character there, we can see what these look like
. Get a nice preview there is that short walk
and you can move in any direction. So that's
pretty good. Let's do the same thing for a
jog. I've only got three jog animations so we're
just gonna make this one a little shorter. I
just go to the jog folder jog ford. Should
we go in the middle and then we have jog
medium left and jog medium rights and the usual.
We just got to set these guys too. 0.3
0.3 for run. I prepared five animations for that
. So we've got wide and medium which is just
the animation that we were using before. This idea
of blending blend trees is actually really useful. It's
pretty cool thing that you can do. So let's
go ahead and toss in our animations. We've got
our running animations here. Run should go in the
center and then we've got run left. We've got
one too many fields run rate wide and we have
our wide value and our medium value so wide left
and that medium whereas yeah, medium right William left
marginal at the time scale and go ahead and set
the values. We're just gonna set these two negative
20.5.3. It was negative.3 0.3.6. So
the same thing as they were before. Oh,
this is your.5, sorry. And they've got
one more called Sprint. This is going to have
three fields. Anyone who talks are sprint animations in
there. We have Sprint forward, turn medium,
right, and Sprint forward medium left. I've got
more innovations. I just haven't just haven't really set
them up yet. And there's process you have to
go through for setting up animations. There's a lot
of information on the docks about it, but it
does take some time. So for now we're just
using this. It really is negative one zero and
one. Cool. So you've got a much more
complex tree now. So if you've got direction we
can set and that will determine what direction removed.
We also have speed, which will determine whether we
walk, where we run jog or sprint full tilt
sprint there. That's pretty cool. I'm going to
give us much more realistic moving movement and that's it
. So let's toast it up. So now we're
in the run mood and if we let off the
stick a little bit we start jogging and if we
let out here and more begin to walk and finally
we stop. So that's pretty nice. You may
be wondering how we're gonna get into the sprint mode
and that's gonna require a little bit of coding.
So we're gonna go ahead and add some code to
the character logic script. But right after we had
some jump animations, so you wanna be able to
get over these blocks here and in order to do
that, we need to add some jump animation.
I've got to jump animations that I prepared. We've
got jump section here and we can toss in.
Locomotion idol jump. And we have, yeah,
we also have locomotion. Just regular Locomotion jumps.
This is this is running more locomotive and we can
go ahead and set values for these guys create transition
and create transition. Okay, cool. The thing
you maybe want to right now is like how do
we know when we need to jump and to do
that? We're gonna use a bullying. So we're
gonna make a new boolean input. What's gonna call
this? Jump it. Yeah. So if that's
true our character well john and want to float as
well. It's gonna say jump curve. This is
gonna be how high he jumps. Want one more
for the capsule collider. So we want to have
the capsule collider move with the character and move where
his feet are. So that's good enough there.
We want to set conditions for when you want to
jump. So that's pretty simple. You just want
to say if we're going to jump then jump in
here. Same thing if you're going to jump jump
and we're going to also set an exit condition of
exit time. So just the default condition for leaving
. So that's our completed uh, mechanism animation tree
. This is as far as we're going to go
with this and now we just need to add some
code to support these new values. You'll notice to
on these animations. I've set up Several curves.
So there's this jump animation here and there's a jump
curve which goes from 0-1 and it kind of has
this sort of jump ish type movement to it.
This is just a really quick curve I made to
control the height of the character when he's jumping.
And the capsule collider just basically shrinks the capsule collider
during the height of that jump so that he can
jump over things. Okay, cool. So that's
that's it there. Let's go ahead and start editing
our character scripts for the script. We're going to
add in a couple of things first. We're going
to have the A button control are jumping in.
The B button control are sprinting. So if you
look at this right here, it's just if the
a button occurs, set the ball to jump.
Otherwise set it to false. If you hold be
, you'll be sprinting and we're just going to alert
between this and a sprint speed, which we can
set the sprint speed constant pretty quickly. I'm just
gonna copy it out of another file. I've got
sprint speed. Here we go. So just gonna
set sprint speed to two and that'll just be a
private variable that we have just a concert. And
basically we're just going to as soon as we let
office sprint, we're just gonna make our speed go
back to normal and we actually don't need this because
it's gonna be said anyways, we're just gonna set
the field of view back to normal. So this
is going to kind of move the field of view
in and out. So we're gonna have a wider
field of view while we're sprinting, which just kind
of something that a lot of games do is they
just widen the field of you so you can see
more when you're running faster. You don't have to
do that. But it's just something I think is
a nice touch. And let's make sure that we
have these variables set up in unity. Let's go
to our input manager, product settings, input and
you want to make sure that we have our sprint
button and our jump button set up. So we're
going to set those up real fast. Let's add
a new entry to our list here And we're going
to set that list to 20. And at the
bottom we're going to have a new variable, it's
called the Sprint. We're going to set us a
joystick button three, which if you look at the
xbox diagram is the X button. Oh, actually
wanna set it to two, is the expert three
is Y please please to for this and you can
leave all these just as normal and for our jump
button, we want to have That set to Joystick
Button zero, which as you can see, corresponds
to the a button. A button usually just jump
. So jump, Interesting Button three, we want
to actually set that two. Basic Buttons. zero
. Okay, cool. So those those variables correspond
in our script right here, We've got sprint and
jump, so hopefully this will work. Let's see
. So that looks like the field of view is
being set, but our speed is being overwritten later
. We need to change that and it looks like
we can jump. So that's pretty cool. So
we've got our idol jump, we have normal jump
here and it doesn't look like the idol jump is
actually working. Is this one here? So jump
is true. That should probably be jumping. Not
sure why it's not. Okay, we'll have a
look at that in a second. Let's go back
to the script. We need to have our speed
. If we're sprinting, we don't want to we
don't want to set the speed here so we can
get adequate condition. Okay. If mhm. We're
not holding that button there. Making set the speed
as normal. Otherwise, we've already said it,
and we don't need to set it. So it's
just a quick way of doing that. Let's see
if that made it better and we can look at
our locomotion tree and see those new sprint variables that
we made and see if we're actually accessing those,
So we're still just running, which is not good
. Mhm. Okay, so to get the sprinting
working, all you have to do is you just
need to go into your script, set a new
damn time. I set it to three and then
actually move this input sprint right below your stick to
world space. And what was happening was this was
already setting speed by the time I got here was
already being set. So I want to pass in
like a secondary variable into this guy and then decide
whether you want to use the normal speed value that
just comes out of this method or if we want
to use our sprint speed, which is to and
we're just going to change the field of view over
time. So that should do the trick. Now
let's go ahead and run it old X. And
our character sprints in the field a few changes.
Let go. Always good. So we have a
nice sprinting animation here. Now we want to figure
out what's wrong with the jump. So we've got
a normal jump here, but we can't get our
still jump to work. So for some reason that
transition isn't happening. So let's look into that.
The reason I was happening is I accidentally drew this
line from Locomotion so as you can see there is
not connected to idle. So that's definitely a bug
. So even though this isn't coding, you can
still have bugs in these state state trees. So
let's just set this jump to true and make sure
that that works now. So you should be able
to jump from idle state. Okay, cool.
So now we can jump over running and we can
jump over standing now. The next step is to
actually get our character to move up and down by
some degree. And the way we're going to do
that is we're gonna use our script. So let's
set a let's set up a new method in here
and we want to do that so that when we
jump, we use the animation curve that's stored in
this animation because in each one of these there's a
curve for how high he needs to just