So the code you want to add to have the
jump logic is actually pretty simple. So in fixed
update, what we need to do, just need
to add in a new condition that if the characters
in a jump state, we want to take the
old position, his old wide position and one actually
translate him up based on this jump curve value time,
some multiplier. And we're gonna translate along Vector3.up.
And if he's in the locomotion jump where he's
actually running, we want to move him forward some
amount too. So we want to do that. We
just want to take his current forward uh and multiply it
by some jump distance. And we're going to translate
him along his Z axis. He's basically just going
to go forward. Like that is going to move
in this direction and the other one is moving him
in this direction. We're moving up and forward.
And additionally, we want to move the capsule collider,
We want to change its height based on the
capital collider curve. So we're just grabbing values out of
the state trees were grabbing values from here and here
and finally we want to actually take the camera.
You want to move the camera up because we want
to make the camera jump with him. So the
next step is we need to actually add in these
IsJump methods IsInJump. And the way we're
going to do that is we're just going to say
if the character is neither an idol jump or in
a locamotion jump, we're gonna go ahead and
say that he's jumping. So in order to do
that, we need to add in uh, this
reference to the capsule collider and we want to have,
so you won't have access to his capsule collider
Want to give him some jump distance. You
want to have that multiplier. Now, we need
to also set the capsule glider so we're going to
do that and start. We're gonna set the capsule
collider equal to just grab the component and we're just
gonna do it that way and the capsule height.
We're just gonna store it on start. And finally
we just need to change this because that actually said
base. So you don't want to have it's a
base. You want to have a base layer.
So also I think that we need to change this
from gamecam.transform. We actually want to move the
parent rigs. They want to change is the parent
rig, And, rig. Okay? Cool! So we'll
probably have to encapsulate this field. Hit Encapsulate. It
make sure that you only give it a read only
value and stick this in our public variable section.
All right. That'll do it. See if that
works. Parent Rig does not exist. Oh, gamecam.
parent right? We need to do that.
There we go. So hopefully we'll jump now and
the camera will jump with us. And the capsule
collider should change height too. Let's click on that
just to make sure. Okay, again, we'll
be able to see the height over here. Okay,
lets it play. Oh turn on the Xbox
controller. Whoa, that was a little extreme.
Why did that happen? Let's have a look at
the code real fast Vector3.up translate. So we
actually needed to make this not a parent rig transform
right here. We need this just to be the
normal transform position and that should do the trick now.
So let's just make sure that works. Yeah.
Okay, cool. Now I've got a nice
jump and the camera moves with our character looks good.
So that's the end. I think we have
everything now. We've got our look, We have
our 3rd person view, we have her behind the
back camera, the ability to re center using the
targeting and we have pivoting as well as jumping so
we can jump over these boxes. That's like a
pretty nice, pretty nice place to stop. I
think we should maybe make some pre fabs out of
these controllers just so we can reuse them in another
scene and I grabbed my camera, drag it down
into here and create a prefab. I'm going to
apply the settings to this prefab. Let's open up
another scene and test them out like a real game
level. Save changes and we're going to load this
same level that is in this game just for testing
purposes. So we can see sort of the parallels
of how the game works out. So we're gonna
go ahead and drag in our main camera, our
prefab section, and we're just going to delete the
old camera and we're gonna revert the prefab is just
to make sure we get the most current values.
Let's see. It's not receiving control and the reason
it's not receiving control as we actually need to drag
our camera into this slot here, you need to
save that. So let's uh let's apply those changes.
Okay, so we'll go ahead and test at
our level. Looks like running around. It's pretty
smooth, appears like we're a little bit off the
ground. I'm not sure if that's just me seeing
things or the capsule glider might not quite be on
the ground, but we can jump around, we
can run over things. Oh, that was weird
and we can move our camera around, feels pretty
good. So I think that's where we're going to
leave off. So thanks a lot for joining us.
And we hope that this tutorial was was somewhat
educational and fun. And hopefully you'll be able to
use some of these techniques in your own projects,
See you next time.