Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,030 --> 00:00:02,460
The anime topic is quite big to tackle this.
2
00:00:02,490 --> 00:00:06,030
It's best to split it up in different functionalities.
3
00:00:06,060 --> 00:00:11,790
In this video, we will look into the enemy scene structure as well as the main script powering all
4
00:00:11,790 --> 00:00:12,540
the enemies.
5
00:00:12,570 --> 00:00:18,480
Let's begin with the scene and if you check the main player functionality, you'll notice the resemblance.
6
00:00:18,630 --> 00:00:24,660
We have a dynamic part, which is the tank and a static one, which is the systems and the final state
7
00:00:24,660 --> 00:00:25,140
machine.
8
00:00:25,200 --> 00:00:30,780
The then image one consists of the tanks kinematic body, while the static one, basically the one that
9
00:00:30,780 --> 00:00:36,480
doesn't move, has all the systems that are responsible for various functionalities as well as the final
10
00:00:36,480 --> 00:00:38,010
state machine controllers.
11
00:00:38,040 --> 00:00:43,920
Looking inside the tank, we can find the actual 3D mesh, its collision shape that is required by the
12
00:00:43,920 --> 00:00:44,760
kinematic body.
13
00:00:44,760 --> 00:00:51,990
And we have two systems here, the communicator and the HP system that need to be here because they
14
00:00:51,990 --> 00:00:57,360
are called when a collision happens and the collision happens with this kinematic body and this is why
15
00:00:57,360 --> 00:01:01,980
we have them here, because it's easier to use and to have a similar structure with the player inside
16
00:01:01,980 --> 00:01:02,700
the tank mesh.
17
00:01:02,700 --> 00:01:05,670
We have two important functionalities that are extra.
18
00:01:05,850 --> 00:01:13,050
Besides the 3D stuff in the tank turret, we have a five point or multiple five points basically from
19
00:01:13,050 --> 00:01:16,560
this is what the actual instantiated projectile spawns from.
20
00:01:16,560 --> 00:01:22,800
And in some cases, if the turret has multiple points that can spawn projectiles, we can have many
21
00:01:22,800 --> 00:01:27,450
and the enemy script will actually cycle through every five points.
22
00:01:27,450 --> 00:01:29,160
So that's really cool system.
23
00:01:29,160 --> 00:01:33,030
And the other part is in the tank body, we have the tank third position.
24
00:01:33,030 --> 00:01:39,150
This is very similar to the player's tank position and this will be used to synchronize the turret position
25
00:01:39,150 --> 00:01:42,030
with the position where it should be on the tank.
26
00:01:42,030 --> 00:01:47,610
But this is mostly useful when we will be animating the turret from the recoil animation.
27
00:01:47,620 --> 00:01:49,650
Now let's continue with the systems.
28
00:01:49,650 --> 00:01:52,140
And in the systems we have the following.
29
00:01:52,140 --> 00:01:59,410
We have the sensor manager that handles all the tanks, sensors such as range field of view request.
30
00:01:59,430 --> 00:02:06,660
We also have the tank mover which handles the movement of the tank using a specified list of 3D points.
31
00:02:06,810 --> 00:02:12,570
We also have the target handler, which is basically another layer on top of the sensor manager to actually
32
00:02:12,570 --> 00:02:16,920
manage the target and to check if one target is visible or not.
33
00:02:16,920 --> 00:02:23,520
And we also have the cover handler, which handles the cover functionality of mostly the retreat finite
34
00:02:23,520 --> 00:02:27,650
state machine, but also in the case of the defensive tank, the attack state.
35
00:02:27,690 --> 00:02:33,060
And lastly, we have the final state machine states that are patrol, attack and retreat.
36
00:02:33,060 --> 00:02:35,490
They both have their own unique scripts.
37
00:02:35,490 --> 00:02:40,950
And we also have the state machine player which contains a unique state machine for each type of the
38
00:02:40,950 --> 00:02:43,770
tank, aggressive, defensive and tactical.
39
00:02:43,770 --> 00:02:48,660
Let's get into the main enemy script, which will be looking in this particular video.
40
00:02:48,660 --> 00:02:54,480
And this script is big, but don't worry, most of it just initializes systems and changes color.
41
00:02:54,480 --> 00:03:01,170
Let's look at how first we are greeted by a long list of export variables, and these variables actually
42
00:03:01,170 --> 00:03:04,410
handle exposing these at the inspector level.
43
00:03:04,590 --> 00:03:10,980
This is easier to use when iterating through various numbers or for people that don't know how to code
44
00:03:11,070 --> 00:03:12,930
and are more towards game design.
45
00:03:12,960 --> 00:03:17,700
These are important because you can customize all the tank instances using the same parameters.
46
00:03:17,730 --> 00:03:22,890
Next, we do have some components, but in the ready function or the initialize function that is called
47
00:03:22,890 --> 00:03:24,990
once the enemy gets instantiated.
48
00:03:24,990 --> 00:03:27,120
We have a lot of stuff going on here.
49
00:03:27,120 --> 00:03:29,130
There are a couple of things that I want to point out.
50
00:03:29,130 --> 00:03:33,750
Both the enemies and the player have the metal tag type, either enemy or player.
51
00:03:33,750 --> 00:03:40,530
We have some more initialization here, either down by using the dollar sign or by getting the no path.
52
00:03:40,530 --> 00:03:42,280
So both of these are valid in Godot.
53
00:03:42,330 --> 00:03:46,500
Here we initialize the color of the tank will go for it in a second.
54
00:03:46,500 --> 00:03:49,500
And from this point forward we have a lot of systems.
55
00:03:49,620 --> 00:03:55,290
So we have the final state machine, we have the tank mover, the HP system that sends our manager,
56
00:03:55,290 --> 00:03:57,210
target handler and so on, so forth.
57
00:03:57,240 --> 00:03:59,880
So most of these are very, very similar.
58
00:03:59,880 --> 00:04:06,720
What is important, and I should mention, is that some of them do require more parameters or require
59
00:04:06,720 --> 00:04:10,920
references to other systems and others require less information.
60
00:04:10,920 --> 00:04:14,400
So in order to do this, I had two options.
61
00:04:14,400 --> 00:04:20,430
The first one that I used initially was to have all the parameters specified in the Initialize function,
62
00:04:20,430 --> 00:04:25,920
but that turned out to be not ideal because the parameters will increase or will decrease or will change
63
00:04:25,920 --> 00:04:27,570
position and so on, so forth.
64
00:04:27,570 --> 00:04:29,100
I found a better way to do it.
65
00:04:29,100 --> 00:04:32,730
Basically the initialize of every system gets a dictionary.
66
00:04:32,730 --> 00:04:36,270
We've keep our values and the key is the parameter.
67
00:04:36,270 --> 00:04:40,860
While the value is the actual value of the parameter to know exactly what keys go where.
68
00:04:40,860 --> 00:04:46,710
In each system I've created an enum called Params that contains what components this particular system
69
00:04:46,710 --> 00:04:47,160
needs.
70
00:04:47,340 --> 00:04:52,500
So for example, in the case of the sensor, we do have some variables like should use a field of view,
71
00:04:52,500 --> 00:04:57,480
a should use request a reference to the parent or detection range and the tank object.
72
00:04:57,480 --> 00:04:59,490
So here we have multiple things.
73
00:04:59,570 --> 00:05:05,640
Either just some values or some other systems or even references to this particular script.
74
00:05:05,660 --> 00:05:11,360
And of course, some are bigger, some are smaller, depending on what other systems they need to use.
75
00:05:11,390 --> 00:05:17,840
Some systems such as the HP system or the target handler who have callbacks, for example, we hook
76
00:05:17,840 --> 00:05:21,550
up to on damage taken and destroyed from the HP system.
77
00:05:21,560 --> 00:05:27,410
Basically, these are functions that are called either when a projectile has been registered to hit
78
00:05:27,410 --> 00:05:33,740
on this enemy, or even if the enemy was killed by having its HP less or equal to zero.
79
00:05:33,740 --> 00:05:39,650
And there are some other callbacks that we can find here, but basically most of this is initialization
80
00:05:39,650 --> 00:05:42,260
in the process function that happens every single frame.
81
00:05:42,270 --> 00:05:44,990
We set our parameters for the final state machine.
82
00:05:44,990 --> 00:05:48,890
And by the way, this is how we provide parameters to the final state machine.
83
00:05:48,890 --> 00:05:54,830
We called set parameter and instead of having them written down, I've opted to use globals.
84
00:05:54,890 --> 00:06:01,670
So Englobal's you'll find a list of all the parameters that can be used in the state machine.
85
00:06:01,940 --> 00:06:07,070
This is also to avoid the mistakes of typing, of just having like a typo in nothing works anymore.
86
00:06:07,070 --> 00:06:12,710
And also I have the states of a state machine go to here so that no longer need to hardcoded when we
87
00:06:12,710 --> 00:06:14,870
actually want to reference a particular state.
88
00:06:14,870 --> 00:06:22,490
And in this case it's the retreat and the retreat percentage is a number basically saying how much percentage
89
00:06:22,490 --> 00:06:25,670
of the life should be remaining before we can actually trigger the retreat.
90
00:06:25,670 --> 00:06:28,910
And I think for the aggressive UI, it's below 20%.
91
00:06:28,910 --> 00:06:34,430
The start function is as important as the enemy instance first needs to get created initialized and
92
00:06:34,430 --> 00:06:37,190
then to start actually executing the final state machine.
93
00:06:37,220 --> 00:06:42,500
This function assures that the final state machine doesn't have is enabled parameter until everything
94
00:06:42,500 --> 00:06:44,540
is ready to not create possible message.
95
00:06:44,540 --> 00:06:50,690
So the state machine will actually don't do anything before this start is called because the enemy will
96
00:06:50,690 --> 00:06:55,580
get instantiated at the 000 and we need to move it first to a different position.
97
00:06:55,580 --> 00:07:01,310
And then from that on, start calculating what's the path to the patrol point or where the enemy is
98
00:07:01,310 --> 00:07:03,980
actually in range of the specified position or not.
99
00:07:03,980 --> 00:07:06,470
So this is critical to have this function.
100
00:07:06,500 --> 00:07:11,720
The next two functions are about changing the color and here have the important things.
101
00:07:11,720 --> 00:07:18,830
So first we create the material called highlight material and we call change material to the root node
102
00:07:18,830 --> 00:07:19,790
of the tank mesh.
103
00:07:19,790 --> 00:07:23,450
And this is actually a recursive function, which we'll see just in a second.
104
00:07:23,450 --> 00:07:27,740
But basically what this does is goes through every element, every child of this one.
105
00:07:27,740 --> 00:07:32,870
And if the child is a mesh instance, then it'll change its first material to this specified.
106
00:07:32,870 --> 00:07:38,960
One, of course, after all of these meshes got the new material, then we can pick the color corresponding
107
00:07:38,960 --> 00:07:39,620
to the theme.
108
00:07:39,620 --> 00:07:41,840
Then we can apply that color to the highlight material.
109
00:07:41,840 --> 00:07:44,090
And let's quickly check the change material.
110
00:07:44,120 --> 00:07:47,450
He gets the current node and the material, and then it takes all the children.
111
00:07:47,450 --> 00:07:51,120
So if you're going to the tank tank mesh, it gets the tank turret and the tank body.
112
00:07:51,170 --> 00:07:56,360
Since those are not actually mesh instances but just specials, they go inside and here is that normal
113
00:07:56,360 --> 00:07:56,690
mesh.
114
00:07:56,690 --> 00:07:58,430
It actually will go inside of this one.
115
00:07:58,430 --> 00:08:03,140
And then here is this one, which is the mesh in stores and it'll change the material for this particular
116
00:08:03,140 --> 00:08:03,350
one.
117
00:08:03,350 --> 00:08:05,690
So this is how this change material works.
118
00:08:05,690 --> 00:08:10,880
And there is a small pack here because for this particular object, I've set up the material render
119
00:08:10,880 --> 00:08:12,140
for the second position.
120
00:08:12,140 --> 00:08:13,520
So it is actually a problem.
121
00:08:13,520 --> 00:08:17,840
But in your use case you might just remove this and it should work just fine.
122
00:08:17,870 --> 00:08:23,120
Of course, for every note we need to call back change material, but we have this particular child
123
00:08:23,120 --> 00:08:27,290
node and this will actually stop executing once no child is found.
124
00:08:27,290 --> 00:08:33,440
So basically, if it reaches, let's say, really deep down node like tank buddy after this was passed,
125
00:08:33,470 --> 00:08:34,760
then it would get the child nodes.
126
00:08:34,760 --> 00:08:39,230
This will be a list of zero elements and it will no longer call change material.
127
00:08:39,230 --> 00:08:44,600
So basically this is how the change material recursive function works and it nicely changes everything.
128
00:08:44,600 --> 00:08:50,030
An alternative to this would be just to change material for every single object that makes the mesh,
129
00:08:50,030 --> 00:08:56,600
but that would have been a task that is actually time consuming because if the mesh changes in any way,
130
00:08:56,600 --> 00:09:02,090
then we have to hardcoded every single mesh that's inside and make sure that we covered everything.
131
00:09:02,180 --> 00:09:04,010
So basically this solves this problem.
132
00:09:04,040 --> 00:09:08,600
The other two functions are called by the state machine player and they are the following.
133
00:09:08,600 --> 00:09:11,990
An update is called at every single frame based on the state.
134
00:09:11,990 --> 00:09:16,130
If it's patrol, attack or retreat, we actually call on update there.
135
00:09:16,130 --> 00:09:21,800
So instead of process, which if we use process in all of these states, they will get called at the
136
00:09:21,800 --> 00:09:22,430
same time.
137
00:09:22,430 --> 00:09:25,910
So it would be like the tank patrols, attacks and retreats at the same time.
138
00:09:25,910 --> 00:09:31,580
By using this, we actually make sure that an update gets called only when the state machine actually
139
00:09:31,580 --> 00:09:32,960
plays the current state.
140
00:09:33,230 --> 00:09:34,970
So this is really important.
141
00:09:35,000 --> 00:09:41,450
In some cases, we don't actually run or need to run a particular state every frame to use its benefits.
142
00:09:41,450 --> 00:09:48,530
We just need when on a state is entered or left and call specific initialize function or remove objects
143
00:09:48,530 --> 00:09:50,450
or destroy objects if the state was left.
144
00:09:50,570 --> 00:09:53,960
So on state machine enter, we have both sides of the transition.
145
00:09:53,960 --> 00:09:58,880
The state that the transition is from to the state that where the transition is due and of course in
146
00:09:58,880 --> 00:09:59,420
the from.
147
00:09:59,560 --> 00:10:02,430
State will call only if that happens only once.
148
00:10:02,440 --> 00:10:05,170
So it's used for the initializing stuff.
149
00:10:05,170 --> 00:10:10,930
And on the other side we have on entry for states, for example, the farm state in the yeah, we actually
150
00:10:10,940 --> 00:10:14,620
need to call it once and then change it to cooldown or reload state.
151
00:10:14,620 --> 00:10:16,210
This is actually what's going to happen.
152
00:10:16,210 --> 00:10:18,250
We don't need to use the update every frame.
153
00:10:18,250 --> 00:10:24,790
The last parts of these scripts are actually callbacks of various systems that we used in the initialize.
154
00:10:24,790 --> 00:10:31,450
So for example on damage taken is actually called by the HP system and it used to inform the target
155
00:10:31,450 --> 00:10:34,060
handler system to set the target externally.
156
00:10:34,060 --> 00:10:39,910
So basically if the current air instance doesn't detect the player because it's not in any sensor range,
157
00:10:39,910 --> 00:10:45,610
but the player hits this target, then we don't want this to be a sitting duck and not retaliate in
158
00:10:45,610 --> 00:10:46,180
any way.
159
00:10:46,180 --> 00:10:52,990
So for this, we actually call on damage taken and we set up the target so it will follow the target
160
00:10:52,990 --> 00:10:58,930
and seek to kill also by the HP system we have on destroyed, which needs to do a little cleanup.
161
00:10:58,930 --> 00:11:04,510
We first need to clean up the patrol, which is basically the final state machine for patrolling purposes.
162
00:11:04,510 --> 00:11:10,480
And this one hooks the waypoint system and we need to free that so that other tanks can be able to use
163
00:11:10,480 --> 00:11:12,010
this particular waypoint system.
164
00:11:12,130 --> 00:11:14,050
We also will instantiate an explosion.
165
00:11:14,170 --> 00:11:15,400
This is a nice effect.
166
00:11:15,400 --> 00:11:20,740
It's by the a VFX manager and we need to register the instance from the tank debug.
167
00:11:20,740 --> 00:11:24,730
This is the tank debug that you can see on top left if you enable the debug mode.
168
00:11:24,730 --> 00:11:31,360
Lastly, after all of this, we can safely remove the object because this object no longer has any references
169
00:11:31,360 --> 00:11:37,300
to the scene on Target found is called by the target handler and this is responsible to inform the state
170
00:11:37,300 --> 00:11:38,950
machine that the target was found.
171
00:11:38,950 --> 00:11:42,610
So in the state machine we set this up to has target two.
172
00:11:42,610 --> 00:11:42,900
True.
173
00:11:42,930 --> 00:11:48,040
Alternatively, when the target is lost is also a signal received by the target handler and it will
174
00:11:48,040 --> 00:11:53,230
inform the state machine that there is no longer any target or signal hit is called by the communicator
175
00:11:53,230 --> 00:11:53,680
signal.
176
00:11:53,680 --> 00:12:00,040
And this is basically just a small object that is instantiated by one tank that detected the player
177
00:12:00,040 --> 00:12:03,430
and it's sent to a tank that hasn't detected the player yet.
178
00:12:03,430 --> 00:12:09,160
So basically what this does is it receives the signal and if the target is still valid, like it's not
179
00:12:09,160 --> 00:12:14,920
destroyed by other enemies, then the target handler will also acquire this target externally.
180
00:12:15,010 --> 00:12:18,370
So this is used to communicate between different air systems.
181
00:12:18,370 --> 00:12:22,810
If you want to know more about the communication, you should check the communication system video.
182
00:12:22,870 --> 00:12:25,090
This is it for the main AI functionality.
183
00:12:25,090 --> 00:12:28,030
Of course, this is the topmost script of all of this.
184
00:12:28,030 --> 00:12:33,280
We have different systems that we need to go through and also the finite state machine states which
185
00:12:33,280 --> 00:12:36,790
are basically finite state machines in their own particular rights.
186
00:12:36,850 --> 00:12:41,350
Let me know what you think about this in the comment section down below and I'll see you in the next
187
00:12:41,350 --> 00:12:41,560
one.
20505
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.