Okay, so welcome back, we're going to be
setting up some mesh colliders on the terrain right now
just because we want to make sure that the character
doesn't fall through the world. It's always a good
thing. So just select all of the mesh items,
add component type in mesh collider and then you'll
see that each one of the meshes has its own
has itself is a mesh collider. You also want
to set a rigid body on all these. So
the physics calculations work. So this type of rigid
body, add it. I like to make this mass
really huge. All that doesn't matter. Um Turn
off gravity which means it won't follow the floor or
like fall into oblivion. Uh you want to make
sure that it is kinematic so it doesn't move.
And you also want to make sure that the character
has a rigid body as well. So we're gonna
add a component to him at a rigid body.
We also had a capsule collider. Yeah, we're
basically rebuilding the character control and unity, but this
just tends to work a lot better. So for
the beta character who wanted to drag in his physic
material that's already pre made and we want to just
resize this capsule glider so it fits him better or
her. It's really hard to tell. Um so
.5 is a little big, we'll make it .4
and we're going to move this Y value. So
we're gonna go with a Y value of 0.97 It's
about as tall as it is. Yeah. And
we want to move the height so that it is
Uh two meters tall so that that it's a lot
better. Okay, cool. So the rigid body,
you can just estimate the mass. I feel
like, I don't know about 100 is probably good
enough and you want to make sure that it is
using gravity and that should do us all right.
So now we're ready to um to save this.
Let's do the same thing in our other scene.
So we've got our debug scene over here that we're
just testing locomotion in and you notice that this hasn't
been set here and the way that you want to
transfer the values over since we have a prefab for
our character set apply and then go back and you'll
see that the beta character now has all of those
things attached to him. So that's really handy. Okay,
so the next thing I want to do is you
want to set up the characters Mecanim, animation trees.
So we'll go into his character controller here.
We want to start dragging in some animations. So
you want an idle animation first. And for that
we're gonna use this player idle animation. So let's
preview that really first and let's make sure that it
worked cool. It's subtle but he's idling. So
what you do to get that in the Mecanim trees,
you just find the animation, drag the clip
into the tree and hopefully character of side animating.
He fell through the fell to the floor, see
what happens. And it's probably because we did not
add mesh colliders to our world. So we should
probably do that. So add mesh colliders to both of
these for the roof. We probably actually don't need
one. So you can you can remove that.
We'll just add it to the to the main floor
. And we need to also have a rigid body
component. So the rigid body same thing. Get
a big mass. Turn off gravity. Turn on
kinematic. Yeah, not falling through the floor now.
So if you'll notice I got a bit of
a problem here. He's not moving So to do
that, we want to extend this animation tree and
create a new node in our state machine here for
running. So to do that, let's have a
look at the other animations we have available to us
. And what we want to do is create a
blend tree and what a blend tree is is a
node that can take an input and then blend between
various various nodes based on that input. So it's
really great if you want to have a speed of
one, be a walk, a speed of two
be a run and a speed of five be like
a sprint or something like that. So in our
new blend tree, we'll just call this thing locomotion.
And we're gonna want to drag in our run
animations. It sounds like in our animation folder.
We got running animations for run. We've got this
animation here. It's just our character running in a
straight line. So go ahead and use this one
drag that into our country just by going add motion
field searching here and we can just type run and
then selecting that animation. Okay, cool. So
now we've got this blen tree right now. It's
not really blending. It's basically just the same thing
as if we just drop the animation in on this
layer and we want to be able to blend between
different values based on like a direction that the characters
running. So to do that we're going to go
to our animations again. We're gonna have a look
at what runs we have, we've got a run
left and never run white right, and we have
them for medium wide and short. So we can
blend between those runs. So let's go ahead and
do that. Mhm add new fields to this.
So at a motion field I had one more motion
fields. And what we want to do is want
to drag in our run animations. So let's make
sure that these work first. Just test them.
Okay cool. We've got our character running in a
circle so what so click on the country and Dragon
run right and Dragon run left. So we want
to do is want to we want to on click
automate thresholds and these are the thresholds for the input
value that we're going to be feeding in and what
their what they correspond to. So for running left
we're gonna call that negative one. I'm gonna call
running forward zero. I'm going to call running right
one. And you want to adjust the time scales,
you want to homogenize them. And basically this
means that one loop of the animation is now the
same length, three twenties animations. So they'll be
sped up or slowed down to make them all the
same length already. So let's choose our parameter.
Right now, we have no parameters in our animation
controller. So let's add a new one, give
me a float, we'll call this direction. Cool.
So now we can preview this blend tree and
if we just slide this slider we can see our
guy run right, or left. So cool.
We now know that our animations are working pretty well.
This preview is super handy. So now let's
set up a transition between these two things. It's
called a blend, three Locomotion. Even though it's
really just running right now, do you want to
right click this, make a transition and make a
transition. So you want to know what you're basically
saying. The character should be able to run from
idle and should be able to go to idle from
run. So we want to here you just want
to make this uh we want to make some condition
for him running. And to do that. We're
going to make a new thing called speed. So
make a new float. So when he runs faster
than some Value, that means we should enter into
the locomotion state. So we're gonna set that value
speed to greater than .5. So now our state
machine will enter into the locomotion state if this parameter
called speed is greater than five and that's it for
that. And now let's make our transition out.
We want to do here is say if the speed
is less than 0.5 takes it Actually at some .05,
that will make him slow down. So this
would basically be if you let off the stick it
will transition back to idle, which is what we
want. Okay so here we want to make sure
that atomic is unchecked. Basically. What this means
is if atomic has checked this locomotion note has to
go all the way to completion before it'll time out
And we want to be able to stop whenever
because you don't want to have the user press forward
on the control stick, expect to stop and they
let go and then stop three seconds later when the
run cycles finished. So I want to make sure
that atomic is unchecked. Mhm. Alright great.
So let's check this out real fast. Let's see
if we've got what it looks like when the character
starts running right? The blend looks pretty good there
and let's see what it looks like when he stops.
Perfect. Alright cool. Now let's make sure
that we're actually supplying these parameters to the animation controller
now and the way they were gonna do that is
through a script on our character. So let's save
our senior fast and on beta. Just implicated him
on beta. We want to create a new script.
So we're gonna add component. We're gonna call
this script character logic. So actually probably character controller
logic is the logic behind our character controller. We're
gonna choose C Sharp as our language created and added.
So we're going to open this guy up and
want to develop. Now once the script loaded,
you'll see that there's actually a bunch of code that's
already in there. And what that comes from is
basically there is a file in this data folder called
the script template. That's right here. And what
this text file is is basically just whenever a new
script gets made, all of this stuff is automatically
supplied. What I've done here is I've made region
tags for each one of the parts of the file.
So we've got our unity event functions like uh,
start update, draw, gizmos, things like
that. We've got a section for methods, section
for properties in a section for variables. So this
is pretty useful and it's just really handy when you're
creating new classes a bunch. All right, let's
go ahead. And our logic in here.