♪♪
♪♪♪
♪
Hi, everyone, I'm Jeremy Gibson Bond
and welcome back
to the Unity Certified Programmer Exam Preparation Course.
In this video, we're going to be
looking at your next challenge, which is adding animation
to both the enemy and the player in the stealth game.
Let's take a look at what it will look like
when you finish this challenge.
Here I am in Unity, I'm going to press Play.
You can see here's my character,
I'll go ahead and maximize this.
Here, you can see my character;
this is a character from the adventure game,
that is up on the Asset Store by Unity.
You can see my character uses the standard animations
from Standard Assets,
but there's something new here, which is,
whenever she goes into cover she spins around,
she creeps along cover,
and she stops at edges,
she doesn't stop at inside edges,
but she does stop at outside edges,
which keeps her from running into our robot
that we animated in the previous challenge.
You can see that this robot now turns and walks,
and it will turn left or right properly
based on which direction it's turning.
That's what we want to do in this challenge, of course,
they interpenetrate now and that's totally fine,
it's not a problem,
we're going to be adding that later to the game.
Now, let's start by taking a look at the player herself.
This is inside of the starter project,
as opposed to the finished version that I just showed you.
When I click on the Player,
you'll notice there's a lot of code over here,
there's a lot going on that figures out
how to go into cover and where the edges of cover are,
and all this other kind of stuff
that honestly for this challenge you don't need to worry about,
you're more than welcome to read through it
and understand how it works,
but for this challenge,
all you need to do for the player is work within the Animator.
Here within the Animator,
this is the same Animator that's in Standard Assets.
You can see that it's designed for a character that can jump,
which is airborne, and crouch, which is the crouching state.
Both of those states are irrelevant for this game,
so you need to turn off the transitions
to those states from Grounded,
Grounded is the normal running around,
that our character does do.
You can see I've added two parameters,
here inCover and Creep.
So, inCover is checked when our player
has gone into cover and is false when our player is not in cover,
and then Creep left or right is negative if she's moving left,
and positive if she's moving right.
These values will enable you to set up
a new state that there's a nice space for it right here,
that is going to be an inCover state
that your character will go to
when inCover is true and exit when inCover is false,
and then within inCover you should set up a blend tree,
that allows you to use the Creep value
to set what her animation looks like creeping left and right.
Here, if I double-click on Grounded,
you can see a Blend Tree inside of Grounded.
That's where the Blend Trees are,
and that's a good example of a Blend Tree.
That's the Animator on the Player character.
Now, where are you going to get these animations?
Well, we have pulled some new animations in.
If you open up Adventure Player,
Cover Animations from Mixamo,
there are three animations from Mixamo,
there are Cover Idle,
Cover Sneak and Right Cover Sneak,
so Left Cover Sneak, and Right Cover Sneak.
These are all set up for your player already,
but I just wanted you to know where they were
in the project hierarchy.
Speaking of animations,
all the new animations for the ACS17
are also by Vladimir Tim, the creator of the model.
and you can see all of them here in the Animation folder.
Now, the Enemy is somewhat different.
If I select the Enemy,
I have to go into the Enemy and click on this ACS17
to get an Animator.
You can see in this Animator
that there are a lot of different states
that we could use on the ACS17.
But, the only states that I'm going to use
in this challenge are ACS_Idle,
which is what we're going to do when the bot is not moving,
when standing there waiting at a waypoint.
ACS_Walk which is what we're going to use
when the bot is walking forward
and then ACS_TurnLeft and ACS_TurnRight,
which are the left and right turn, respectively.
The difference here, is rather than working
in the Animator as you did for the Player,
I really want you to execute this entirely in code.
I'm going to show you a little bit about how we're going to do that.
The first aspect of what I've added to allow you to do this
is a little bit on the Enemy Nav script,
that tells us the turn direction.
This is calculating using a cross product
and you take a look at how it works in there,
but Turn Dir is negative when we're turning to the left
and positive when we're turning to the right
and zero when we're not turning at all.
You can use that to determine
which way to turn when the Mode
is set to either Pre Move Rot or Post Move Rot.
When the Mode is Move,
we should be walking forward
and when the Mode is Idle or Wait,
we should be in ACS_Idle state.
Now, that animation is going to be controlled
by the ACS17 Animation Manager script,
that I've placed onto the ACS17 child of enemy.
One thing that's cool here
if you think about the structurally,
is say you replaced this robot
with a completely different character,
that still use the same navigation
to patrol into waypoints and stuff,
but we've replaced what it looks like.
This way, we can replace the animation
and just base that animation off of the Enemy Nav script
rather than having it embedded into the enemy
and having to change it
when we changed out the model.
Looking at this, you'll see there's not much here
in the Animation Manager yet,
but I do suggest that you use anim.CrossFade("ACS_Walk", 0);
Let's break down this method,
anim is a link to my animator,
and you can see
I've Required Component type of Animator up there.
Then, we can tell that animator to CrossFade
to a specific named state like ACS_Walk
and then the zero there is a CrossFade time of 0.
If we set the CrossFade time to 0,
then we can pass this to the Animator
as many times as we want
and if it's already in that ACS_Walk state,
it'll just animate nicely,
and that's what you see
in the example solution that I have.
Your Bonus Challenge, for this time is to figure out
how to make that 0 into another number,
so you can blend into the different states.
But, what that's going to require,
is going to require you to only call this once
to start the transition to the new state,
and not call it repeatedly because if you call it repeatedly
with a number there other than 0,
then it'll just continually start that transition
and it will never complete
and finish the transition and move completely
into the new state that you're trying to CrossFade into.
So, that's it for this challenge,
there's a lot more that has been added to this project.
Again, you don't really need to worry about it here,
but if you want to you can go in and see how I've started
to create the StealthPlayerCamera
that will actually track the Player,
and in later challenges
what will happen is when she's uncovering,
she's moving close to an edge just like Metal Gear Solid,
it'll zoom in to allow us to peek around the edge
and cool stuff like that.
But, again,
you don't need to worry about that too much right now,
it's just something fun to take a look at if you feel like it.
All right, so I hope you enjoyed this challenge,
and I look forward to seeing you in the next video. Thank you!
♪♪
♪