Game Advanced Alpha Type Version 1
Hello everyone
This is Kim Hyunjin of FPS game development
In this lecture, we will learn how to apply
the model that can be downloaded
through the Asset Store to a enemy that is in a capsule
And utilizing Animator and the animation clip
I will implement so that the right animation can be executed
Application of an enemy model
This time, the capsule based enemy
will be changed into a zombie shaped model from the Asset Store
I will select the Window menu from the upper editor menu
Press on the Asset Store button
And then press the Search online button
When the Asset Store website pops up
I will search for the word zombie in the search engine
Select the zombie asset
Next, press on the add to the asset button
Please confirm it
Then chose the open button from the unity
And press on the open button from the unity editor
As the package manager opens up
you will be able to see the zombie page
Press the download button over here
If it has been downloaded, press on the import button
Next, when the browser window opens up
Press the import button which is placed in the bottom right
If the zombie isn't selected like this
in the package manger
Next to the + button in the upper left side
There is a menu called package unity registry
If you select it, it will dropdown like so
Choose the My Assets category from over here
This category holds all the assets
that we have bought from the Asset Store
So select My Assets and
and if we search zombie in the search engine
Out of the assets that we have bought
It will look for the zombie
You can add over here as well
If it has been added, there will be
a zombie folder in the project window
Select FBXs folder over here
I will use Zombie 1
Drag Zombie1
and I will put it in Enemy
Drag and attach it to Enemy
But as you can see, the zombie's color is pink
This means there is an error in the material
When we created the project
We used URP mode
So from the Asset store
If you have received a certain asset
and it is in the color pink
The material that is used over here
needs to be revised a little
I will choose the Materials folder that is below the zombie folder
Then there will be two materials
Select both of the materials. All of them
And select the Edit menu that is on the upper left side
If you leave the mouse on the Rendering menu that is in the bottom
It will expand to the right like so
Select the Materials menu
And Convert Selected Built in
If you choose the menu called Materials to URP
It allows this material to be
revised according to the form of the URP
Press it
Then it will pop up in a window
Press on the Proceed button over here
Then the material will be revised like so
the shape of the zombie will show up in a normal way
as you can see over here
Now, I will hide the capsule that is in the color red
Like this, I will make sure the zombie shaped model
can be clearly seen
Select on Enemy GameObject
From the Inspector, I will inactivate
a component called Mesh Renderer
Then you aren't able to see the shape of the capsule, right?
And the zombie is up in the air so
Choose the zombie model that was inside the Enemy
And the y value of the Inspector will be chosen as -1
Then you can see that it stands on the ground like so
When you develop the project for the first time
The functions should be implemented using the basic shapes
And later on, getting help from the asset store
or the art department
The progress of changing the basic shapes into
beautiful and cool forms can be proceeded
Enemy Animation
Now, the zombie models will be applied
so that the animation for each condition
could be implemented
For the animation to be applied to this model
We need a component called Animator
You can see that it is attached over here, right?
If it isn't attached
Press the Add component button
search for Animator
and then add it
And select the zombie folder that we have downloaded
Go into the Animations folder
There are several animation files
Using these certain files
We will enable the zombie model to execute the animation
First, we need to generate a file
Select the Assets folder
and create another folder
Press the + button from the project
and let's say the name of the folder is Animations
Then, after selecting the Animations folder
Press the + button and
Choose the Animator Controller menu in the middle
Then a file like this will be generated
I will name this file as ZombieAnim
If you double click on the file
the a window like this will pop up
An animator window
In this zombie folder that we have downloaded
there are animation files
Placing these files over here
I will enable it to operate
At first, we have divided the condition of the enemy
and how it will transfer
into a diagram
Place the animation similar to this
Transition like so
I will set it so that the animation will change
In this animator window, using the wheel of the mouse
It can be expanded and shrunk
Next, click the wheel button
to move it around
Make sure to remember this operating method
First, when this Animator is operated
It will be operated in this node called Entry
so in this model with the Animator
At first, what action it should take
The animation that you want to enable
should be left over here
From the animation folder in the zombie folder
we will upload an animation file
named Z Idle
Let's select and drag it
It will come up like this
If there isn't anything inside the Animator
If there is no animation file
It will be automatically connected to the Entry like this
I will change the name
After selecting this Z Idle node
I will change it from Idle to Inspecttor
If you play it
The zombie won't be able to operate the animation
Because if you select the zombie game object of the Hierarchy
the Animator component will be attached
In the attribute called Controller
the Animator that we have just created should be included
So inside the Animations folder which is in the Assets folder
We have created the ZombieAnim
Drag the Animator file
and attach it over here
We need to set it this way so that
the animator which was in the Animator browse
can be executed
I will try to play this
Since the player is too close
It will be in a moving condition
Place it further
and play it once again
Like so
We can see that the animation which
seems as if it is breathing is being operated
When the player has moved closer
The Enemy is moving, right?
Then which animation do you think we should operate?
The walking animation
or the running animation
Therefore, in this Animator file
we will add one more animation
Selecting the animation folder again
which is inside the zombie folder
An animation file called Z Run Inplace
will be dragged on
I will change the name
Let's name it as Move
If it is converted from Idle animation
to the moving condition
The Move animation should also be
operated as well
So from the node of Idle animation
Press the key on the right
Select a menu called Make Transition
It is a transition
We will create a transition
Then, as you can see the line
will follow the mouse point around
Therefore, if you bring over the mouse
to the Move animation node
You can see that it attaches
And click on the Move
Then, like so
These two nodes will be connected
If it has been connected, I will play it
Separate the Animator window
so that it can both be seen at the same time
I will change the setting
If I play it, we can see what animation is
being operated through the Animator
After Idle has been operated
it has suddenly changed to Move, right?
Select this transition
and it can be eliminated as well
If we play it
You can see the Idle is still being operated
I will connect it once again
And you can select this transition
The default setting is complete, once you have selected it
If we play it in this condition
this Idle will be operated
and it has passed automatically, right?
The reason is because this menu called
Has Exit Time was chosen
Whether the Condition in the bottom
is present or absent
makes the option operate in a slightly different way
The Condition isn't here
therefore, this transition
once the previous animation has been operated once
it will automatically pass to the
animation that is connected
If it is left in this condition
When it is played, the Idle will be operated once
and the phenomenon of it moving through Move will be seen
What we desire is when the player is close
and the enemy is in moving condition
That is when we want the Move animation to be operated
So the condition that enables the passing
needs to be set
If you look at the Animator window
There is the Layers and Parameter
Select the Parameter tab
And then this is the + button
Press on the + button
and select the Trigger menu
And let's name it Move
This Parameter can be used as a
condition for the transition
Select the transition
from Idle to Move
From the Inspector, if you look at the bottom
There is a + button in the Condition menu
Press the + button
Then a Move will be
set automatically
Currently in this Parameter
The Parameter called Move is the only one there
which is why Move will be selected automatically
If you did dropdown
and made multiple Parameters
You can select from here
Previously, it had passed automatically, right?
But now
It doesn't pass even when the Idle is completely executed
This condition of transition that passes over
This Trigger called Move
needs to be operated once in order to pass
So whenever we want to
we can enable the Move animation
Through what?
By operating this Trigger called Move
Then, the method to operate the Trigger called Move
needs to be learned
It can be done through the Animator component
Let's come back to the code
Open up EnemyFSM script
In the global variable, I will make a variable that
has a Animator component
which is attached to the zombie game object
Animator Variable
There is a class called Animator
Then let's name it anim
Through the public keyword
we can drag and drop from the editor
or as we brought the navigation agent
We could also use GetComponent
Let's bring the code over for this one
Bring over Animator component
We should hold it in the variable called anim that we have created
I'll type in GetComponent
Which component should we bring?
The Animator component needs to be brought over
That was what we said
But if it is written like this
The Animator component can't be brought over
Go to the editor
This component of EnemyFSM script
It is in the Enemy game object
So in this script
if this GetComponent is simply used
the components in the same line
will be searched through this function
So I mentioned I will find the Animator from here
In the Enemy game object itself
the Animator component is not attached
So it can't be found
Where is it?
It is in the game object called zombie
which is a child of the Enemy game object
So this GetComponent cannot be simply used
I will change it
There is a function called
GetComponentInChildren
Out of the child game object
It plays the role of
finding the particular component
Through this progress, the anim variable is
stored into the Animator component
This anim variable
allows the Trigger to occur
The Trigger called Move occurs when
it is transferred to the condition called Move
So We have already created
the function that will be invoked
when the condition has been transferred
What is it?
We have created a function called ChangeState
So if this State is Move
Then it will continue in the condition of Move
What will it do then?
It will activate Move Trigger once again
So come over to the ChangeState function
In this Switch case statement
If this current CurrState is Move
Let's activate Move Trigger
Hey anim, out of the functions that you have
There is a function called SetTrigger
Through this function
the Trigger will be activated
Open up the brackets and write down the name of the
Trigger Parameter that you would like to activate
We have set the name as Move
So Move
Come back to the editor
and I will try to play it once again
The zombie is in an Idle state
I will adjust the player
and move closer to it
Then it runs over, right?
But it will continue to Move even in an attacking state
So what should we do now?
When it is converting to an attacking state
We have to let the attack animation occur once gain
But prior to that, there is a
slight error over here
I will try to play again
Into a Move state
I will try to create thee
beginning stage of the Idle animation
And move over to the end of the Idle animation
Then, during the Idle animation
there will be a moving stage
It is because of this transition
Select the transition
and the Has Exit Time will have a check mark next to it
This is why
At first, when Has Exit Time
had a check mark next to it
I mentioned that depending on the existence of the Condition
it would operate differently
If the Condition is not there
the Idle will operate
and the automatically connected
animation will operate
But after I have added a Condition
it didn't pass automatically, right?
When did it pass?
It passed after a Trigger called Move has activated
But there is one more over here
Has Exit Time has a check mark next to it
So it won't pass right after the Trigger has been activated
When?
When this Idle is completely finished
When the Trigger activates at that moment
It will pass over to Move
Therefore, in the condition of Move
Let's say the Idle animation
was in its beginning stage
The Trigger has been already activated
But it cannot pass
Why?
Because of the option that Has Exit Time has
So after the Idle is completely finished
Ah the Trigger has been activated
That is when it can be passed over
So according to the code
It is moving toward the play
As the Idle animation proceeds
the animation will be able to see it move
So let's make a check mark next to Has Exit Time
After that, if Trigger is activated
the animation will pass over right away
I will move closer once the Idle animation is about to end
Then you can see that it runs
Now, I will add the attack animation
Drag and attach the Z Attack
And for it to move over from Move to Attack
the Attack Trigger will have to be activated
So a Parameter needs to be added
Press the + button to select Trigger
I will name it Attack
Next, moving from Move to Attack
A transition will be created
Press the right key
Make transition and connect it
Select the particular transition
Uncheck the Has Exit Time
Press + for the condition
Make sure that the Move isn't selected
but instead the Attack is selected
Dropdown and choose Attack
Then, after we finished the Attack
Send it to AttackDelay mode
Then after playing the Attack animation once
Animation for AttackDelay
will need to be executed
Now, the Idle animation
will be set so that it would be executed in AttackDelay condition
One more Z Idle from the project tab
Drag and drop it
Let's change the name of it to AttackDelay
Press the right key from Attack animation node
Make transition and
Connect to AttackDelay
But the Condition won't be added to this
Why?
After the Attack animation is finished
It will just pass over
Then, in the AttackDelay condition
we will wait for the AttackDelay time
depending on the distance with the player, we will decide on
whether we should choose Attack, Move or Idle
So press the right key in AttackDelay
Make transition and
whether we would go back to Attack
Once again, Make transition
whether we would go over to Move
Then press right key again
Make transition
Connect if we should go to Idle
After this animation
whether we should proceed with Attack animation
or Move animation
or Idle animation
is being decided
Like what we started with
It is quite similar to this picture, right?
In a attack delay condition, whether to go with attack
move, or delay
When moving from AttackDelay to Attack
select a transition
uncheck Has Exit Time
Add Condition
It should be Attack, right?
When moving from AttackDelay to Move
After selecting transition
Uncheck Has Exit Time
Press + for the Condition
Set it so that it would pass over when Move activates
Then, moving over to Idle
We should add Condition, but there is no Parameter
So make sure to check if the Parameter tab is set
Press the + button and select the Trigger menu
We will create an Idle Trigger
So from AttackDelay
to Idle animation
Choose transition
Uncheck Has Exit Time
Press the condition + button
Dropdown and choose Idle
Make sure that it is suitable for the situation
and activate Trigger
Come back to the script
The condition that converts for ChangeState
If it is attack, then it would be here, right?
Hey anim, out of the functions that you have
Execute SetTrigger function
Then we should write Attack
Next, if it is in the Move condition
This case will be invoked
The Move animation will be executed
But Idle animation is not there
So we will add one more case
Idle in Case EnemyState
In this case, hey anim, out of the functions you have
I will execute SetTrigger
This means that Idle Trigger will be operated
to allow Idle animation
Look close at the Animator
Play it
It is in an Idle state at first
It will be a Move when I move closer
If it comes closer, it will pass to Attack and AttackDelay
Attack and AttackDelay
During the AttackDelay, if I
move further away, it will go with Move
I will move away further, right?
Once again
I will move away completely
Then you can see that it passes to an Idle state
While you proceed with the project
There will be various animations
For now, the animations related to Attack are
This Attack and Attack Delay, right?
For example, this motion called Attack
Let's say there are multiple types other than this
Then depending on the situation
every animations have to be set
Then this page will become very complicated
So in Animator
there is a function called Sub State Machine
If you press the right button of the mouse in this empty space
You can see the menu pop up
There is a menu called Create Sub State Machine
If you press this menu
Another mode in a different shape will be created
Select the node
Let's name it as Attack Process
Then, this Attack and Attack Delay
Drag and select all of it
Press on the left button of the mouse
If you bring it over to the Attack Process
The + icon will be activated
Then if you move the mouse away
These two animations
will move inside the Attack Process
If you double click on the Attack Process
I will organize the information
Like so, what we have put inside
These two nodes go in
and automatically connect other transitions
So in the Move condition
if it is converted to Attack condition
It moves inside to the Attack Process
which leads to Attack being operated first
and then automatically, Attack Delay will be operated
Whether to go back to Attack
or go back to the layer on the top
and whether to go to Move or Idle will be decided
Depending on the operation of the animation
The Animator window will change as well
Let's try it
Press Play
If we head over to the zombie, it will come in Move
If we move to Attack, it comes over
If we move away further
Going back again to the upper layer
which has this Attack Process
We will operate Idle animation
So when you think that animations have increased
and the types of animations are
in a particular condition
Like so, use the Sub State Machine
in order to organize into groups
This time, when the enemy is attacking the player
we are operating the animation
but also executing print attack as well
The timing of when the print called attack is printed
and the timing of the animation that attacks
will be looked at closely
If you take a look, when it is passed over to an attack condition
You can see that this print attack appears
From Move condition to Attack Process
A print called attack appears on the screen
At the same time, this zombie model will be proceeding the animation
It will take the action of swinging the right hand
So when the right hand is about this far
It should be passed over to the attack condition
But it gives a sign of attack, right when it has started
If this happens, in the player's perspective
It seems likes it is being attacked
even when the monster hasn't attacked it properly
So this print called attack
The attacking point
When the hand has come up this far, by swinging its arm
I will change it so that it will be operated at that time
I will create a script in the project window
Select script folder
Press the + button, C# Script
Let's name it HitEvent
Let's attach this script to zombie game object
It shouldn't be attached to Enemy game object
In the zombie game object
I will drag and attach it
Open up HitEvent script
The Update function is unnecessary, so I will erase it
For the global variable, EnemyFSM component
I will create a variable
I will write public EnemyFSM and call it FSM
And then I will create a function
The function that will be invoked at the exact attacking timing
I will make a function called public void PayerHit
Through this function, the attack being
printed from EnemyFSM will be operated
I will create a function
Come down to the bottom
public void AttackAction
I will print the print attack
Then what was in the ChangeState function
This attack print will be eliminated
And come back to HitEvent Script
Hey FSM, out of the function you have
Operate the function called AttackAction
Then PayerHit
What would happen if it is invoked?
The function that EnemyFSM has
the AttackAction function will be executed
The attack will be printed, right?
What is left is to make sure that Payer Hit
is invoked at the exact attack timing
After you come back to the editor
Select the zombie folder from the project window
Then choose the Animations folder
Double click to open the Z Attack file
An animation window will open up like so
And in the Hierarchy
If you select the zombie game object
the player button will be activated like so
And right below, Z idle has been
selected, right?
If we play it
Like so, you can see the zombie in the preview
Executing the Idle animation
And if you select this Z Idle
It will expand the menu
allowing the selection of Z Attack
and the selection of Z Run Inplace
Modify to Z Attack
and if we press play again
We can see the preview of the attacking animation
Or if we select the mouse of the time line
You can see the motion that fits the location
If we lift up its hands
It won't be attacking
but instead, when its hands are reaching forward
It will be attacking
This part means attacking at the right timing
So depending on your desire of timing
You can move it
Below the time line
In this line that says Z Attack
If you press the right key of the mouse
There is a menu called Add Animation Event
If you select that menu
A small icon like so will be added
if you select that icon
It will say that it has been selected, in a blue color
In the Inspector, animation event
and a menu to add the function
Next, No Function Selected
If you click on that part
Like so, inside the HitEvent
The PlayerHit that is inside the method
can be selected
PlayerHit which is inside the method function of Hit Event
You can see that it has been selected
What happens next after the selection?
When the attack animation is being executed
When it is executed like so
When it has come that timing
It plays the role of executing the function
Then, when you have reached forward
A print called attack will be printed
After the selection of zombie game object
FSM isn't set in the HitEvent script
In the parent game object
I will put the EnemyFSM inside
So,after selecting zombie game object
The Enemy game object that is right above
will be dragged and attached
So what the Enemy game object has
this EnemyFSM component will be put inside
Move closer
You can see that it is able to attack at the exact timing
When the player has attacked the enemy
It will be in a Damaged condition
The animation that occurs during that timing
will be what we create next
The damage animation
does not exist in the Asset that we have downloaded so
We will download it separately
If you open up the URL on the screen
There will be a Zombiehitfbx file
Press the key on the right to download
that file
If it has been downloaded
Select and drag the file
In the project window, in the zombie folder
Move it inside the Animations folder
And select the Zombiehitfbx file that has been added
If you look at the Inspector window
There are four tabs
Select Rig from over here
And change the animation type to Humanoid
And select Apply
And if you expand this zombie hit
There is an animation file that is shaped in a triangle
If you select that file
and copy it by pressing Ctrl+D
Like the animation files on the top
It will come out
I will press Ctrl+D
Then it comes up like so, right?
I will change the name to
z_Damaged
I will drag this file and bring it over to the Animator window
I will change the name of it to Damaged
This damage animation
needs to be executed in any condition
So if you look at the Animator window
There is a node called Any State
What this node is
This model operates Idle or Move
It continues to operate other animation
And if the condition connected to this Any State
is satisfied
It allows the animation to be
operated right away
So this Damaged animation
should be connected in the Any State
So in the Any State
Click the right key of the mouse in order to Make Transition
Connect it to Damaged
And a Trigger should be created
which allows the transition to be operated
The Parameters tab of Animator
Check if it has been selected and press the + button
To add Trigger
Let's name this Damaged
After selecting this transition
I will add Condition on the right
And choose Damaged
To make this Trigger occur
Come over to ChangeState function of EnemyFSM
If it comes in a Damaged condition
we should operate the Trigger
I will add one more below the Move condition
If it is in a Damaged condition in the Case Enemy State
Let's say hey, anim
using the Set Trigger function that you have
We will operate the Damaged Trigger
We will play this
Press the left button of the mouse to attack
So then, Damaged
animation will be executed
But it stops after being finished, right?
After the Damaged action
and then if the damage delay time is over
We have to move to Idle or Move
or proceed the attack
It is being operated according to the code
but in the animation condition
There isn't a transition path to proceed
When we drew this diagram
After it had come to the damaged condition
whether to proceed with delay, move, or attack
had to be drawn
Like so, I will set it so that
this animation can be a transition
In the Damaged animation node
Press the right button
After the Make Transition
connect to Idle
Select transition
Uncheck the Has Exit Time and
Add through the Condition + button
This needs to be the Idle
Make sure to change it to Idle
Press the right key in Damaged node
and connect to Make Transition Move
After selecting the transition that has been added
Uncheck the Has Exit Time
Make sure to check if it has been set to Condition Move
Lastly, in the Damaged node
Press the right button
and Make Transition
to connect to Attack Process
Over here, to the State list
If you bring the mouse over
There is an AttackDelay and Attack
Attack needs to come first for us, right?
So we will select the Attack
Next, select the transition that has been added
Uncheck the Has Exit Time
And then add one more Condition
Let's change the Condition to Attack
I will take a look
If it attacks
Operates the Damaged animation and moves over to Idle
Operating the Damaged animation again and moving over to the Idle
You can see it, right?
Then I will make it approach and follow
If it attacks after the Move
It stops, and then follows
Stops, and then follow again
If it attacks in the middle of an attack
It goes "AHH!" and then attacks
"AHH!" and then attacks again
We can check its movement
Next, when it is in a dead condition
we will set the animation that will be operated
Out of the animation list
There is Z Falling Back
and Z Falling Forward
It wouldn't matter to use either of them
I will use Forward
If you look on the top, there is a tab that is called Base Layer
If you press this tab
It moves over to the upper layer
Change it like so
I will drag Z Falling Forward to insert it
I will change the name to Die
Same for the Die
No matter what condition it is in
It needs to be operated
In order to make it operate from Any State
I will create the transition
Press the right button from Any State node
Select Make Transition
and connect to Die
Making sure that the transition can be operated
I will add a Trigger Parameter
Press the + button, select Trigger
Let's add while naming it Die
And select the transition
I will add a Condition
Press the + button to add and modify
To what?
Modify to Die
So in order for the Trigger to be operated
we have to write down the code
Come over to EnemyFSM script
When it is in the Die condition from ChangeState
It is destructing the game object after a second
We can make this as an animation then
Hey anim, out of what you have
Utilize the SetTrigger function
to operate Die Trigger
Save it and come back to the editor
Play it and let's quickly attack
If it is attacking
it will be in a Die mode
You can see that it disappears after collapsing
But if you want the collapsed condition
to continue longer
Do not destruct it after a second
Set it destruct after 3 seconds
to see the character collapse a little longer
Let's play once again
Attack quickly. It will die in one, two, three, four, five times
When it dies, the character collapsing
needs to be checked for a bit
and then you can see it disappear
Like so, depending on any condition of the Enemy
We have implemented it so that
the animation can be executed
So let's do an overview of what we learned
Overview Application of enemy model Asset Store Window Asset Store Search online Hide the basic shapes by deactivating the Mesh Renderer component of the Enemy
Adjust the transform position value The exterior can be modified through the Asset store or art director after being implemented at the beginning of the project development
Enemy animation Idle animation Create Idle node through clicking and dragging Z Idle file to the Animator window
The first file of the Animator tab is connected to the Entry node automatically The Animator needs to be in the Controller attribute of the object to operate
Move animation Create Move node by clicking and dragging the Z Run Inplace file in the Animator tab
Click the right key of the mouse on the Idle node and click Transition to connect the Move node Create Move parameter by clicking Animator Parameter + Trigger
Uncheck Has Exit Time of Transition, add Move to the condition and write Trigger activating code Animator #4 Animater anim; Bring over Animator component
anmi=GetComponentInChildren Animator; Write on switch condition of ChangeState function anim. SetTrigger Move;
Attack animation Click and drag Z Attack file on the Animator tab to create Attack node Click and drag Z Idle file to create AttackDel node
After connecting from Attack to AttackDelay, do not add to the condition Connect transition from AttackDelay node to Attack, Move, Idle node
Write trigger operating code depending on the situation When a certain animation type increases in a situation, use Sub-State Machine function Enemy animation
Attack animation Click and drag Z Attack file to the animator window to create Attack node Click and drag Z Idle to create AttackDelay node
Connect transition from AttackDelay node to Attack, Move, Idle node Write Trigger operating code depending on the situation
Utilize Sub State Machine function when a certain animation type increases in a condition Damaged animation Z Damaged file into Animator window
Click and drag to create Damaged node Connect to Any State node since it operates regardless of the Enemy's condition
Connect transition from Damaged node to Idle, Move, Attack Process node Write trigger operating code depending on the situation
Write trigger operating code after connecting to the Any state node Adjust the time of Enemy being passed out by modifying the time variable of the Destroy function