Hey there, welcome back to the third person camera
tutorials and Unity in this lesson we're gonna be
working on getting our pivots to be a little bit
more accurate right now, if you look at them,
you can see in the angle value, if
I slam exactly backwards on the stick, I end
up getting angles around uh usually like 160 or
or lower, they're not that accurate. Uh and
the reason for this is because each one of these
animations has a certain condition the gets met and during
that condition it executes a transition period and that transition
period can be anywhere from half a second to a
full second however long you want. So if I
make these transitions a little bit longer, you'll be
able to see that that accuracy goes down even further.
There's 139 and that's because uh the angle values
still being set during this transition period and the character
is moving during that. So it's it's giving us
really inaccurate angle values, so we're gonna learn how
to change that and get it to be a little
bit better. So first of all, I would
just make these not quite as large because they don't,
they don't need to be that big transitions.
Um that's one thing you can do, but the
better thing to do is definitely to uh to spend
some time working on your, on your logic,
if you look at Mario when he runs and if
you slam back exactly on the stick, it makes
a perfect 180 degree turn and this is what the
user expects. So that's what your game should provide
for them. It's the same sort of thing here
in Zelda, if you run and then change direction
abruptly, it's hard to get it to work,
but there is pivoting in this game to there you
go. So it's it's exactly 180 as well.
So we need to get ours to be a bit
more accurate. Then the way we're going to do
this is we need to recognize when these transitions are
happening and make our code react to that and consider
that during a pivot. So it's kind of
unintuitive the way this works and there's not a lot
of documentation on it. But if you look at
the animator controller, it has a method called get
animator transition info and that gives you a animator transition
infrastruct. And what this does is we can access
it just in the same way that we did with
with our with our state info object here. So
we just want to make another one of these info
objects and just query that in the same way that
we're querying it for these pivot IDs, we want
to make another id for each one of these transitions
and it may not be exactly obvious what the name
of the transition is. It's not this year,
it's base layer dot locomotion to base layer dot locomotion
pivot are there is no space between these two characters
here, but there is a space between uh the
word and the arrow on either side. So took
me a while to figure that out. And there's
not a lot of people online who who have much
to say about that. So hopefully this is something
unique, this tutorial provide. So we want to
change that. You want to make two new variables?
Yeah, we're going to make one called locomotion
pivot transition left and locomotion pivot transition. Right now
we want to populate these variables with the name hashes
and we've been doing that just right on our start
with so there we go. The next thing we
want to do is you want to add that code
to our pivot logic. So our pivot method currently
says if name hashes, pivot left I'd or right
idea. Let's add some logic to make that.
Also take into account the transitions. Mm hmm.
So that's good. Let's give that a shot and
see if that makes our our turns any more accurate
. We need to we need to declare transition and
Phil so transition info will be a new variable that
we're going to declare at the top of our script
and made a transition info that there we want to
initialize it at the same time. We initialize our
state info. And since we're just using the first
layer, you can just grab you can just put
a zero here. It's a signal that you just
want the first layer. Okay, hopefully that'll compile.
Okay, great, let's give that a shot
. hopefully we'll be getting values closer to to 180
now Instead of 1:30. So I was 1 78
. That was pretty good. 1 77. But
you notice it's still not quite right. The cameras
turning during the pivot. So we need to extend
this logic year and go into our camera script.
And where we have our behind camera want to add
one more condition to the look direction because the look
direction is going to affect that angle direction because if
you look in our controller script, we're grabbing the
cameras forward factors. So if we're turning the camera,
that forward vector is going to change. So
the easy way to fix that is just to give
it a condition, we're going to make that condition
that it's not in a pivot. So we added
this follow is not in pivot condition. So let's
see what that looks like. Now that's much better.
So we're getting nice values, they're large enough
and our cameras not turning what we're pivoting. That's
it's a pretty good win. And that's it for
this lesson. And then the next lesson we're going
to be discussing how to make a free camera.
So stay tuned for that.