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,650
Let's find out about the retreat functionality.
2
00:00:02,670 --> 00:00:05,700
One of the three states of our agent.
3
00:00:05,760 --> 00:00:11,310
The retreat feature consists of a state machine definition and the state code to make it work.
4
00:00:11,340 --> 00:00:18,120
It gets triggered when the agent's HP drops below a certain value that can be customized for different
5
00:00:18,240 --> 00:00:19,020
behaviors.
6
00:00:19,050 --> 00:00:21,550
Let's start by looking at our state machine.
7
00:00:21,570 --> 00:00:23,400
So this is the first level.
8
00:00:23,430 --> 00:00:28,800
We need to double click into retreat and here to find the following three states.
9
00:00:28,950 --> 00:00:34,110
First, when entered the retreat, functionality will try to find a valid cover.
10
00:00:34,140 --> 00:00:41,040
If a cover was found, then it will go there to that cover and then it will wait for a certain period
11
00:00:41,040 --> 00:00:44,730
in the cover if the cover is invalidated for some reason.
12
00:00:44,760 --> 00:00:49,590
For example, the player moves and has a direct line of sight to the enemy.
13
00:00:49,620 --> 00:00:51,800
Then the cover will get invalidated.
14
00:00:51,810 --> 00:00:53,760
It will try to find a new cover.
15
00:00:53,790 --> 00:01:03,090
If it is false, then this means that this state is no longer available and the air can move to attack
16
00:01:03,090 --> 00:01:04,440
or patrol state.
17
00:01:04,500 --> 00:01:08,220
Let's look now at the code and how everything is put together.
18
00:01:08,250 --> 00:01:14,400
After the initialization step of various objects, we also need to connect the tank mover so that we
19
00:01:14,400 --> 00:01:15,780
have unfinished moving.
20
00:01:15,780 --> 00:01:22,540
But we also have two important timers search for new cover timer and validate cover timer.
21
00:01:22,560 --> 00:01:24,300
So what do they do?
22
00:01:24,360 --> 00:01:29,850
If you checked the patrol state, you probably are aware that when the patrolling gets called on entry,
23
00:01:29,850 --> 00:01:33,300
the new patrol position is picked and the mover is set to go there.
24
00:01:33,300 --> 00:01:38,120
Their own entry happens only once when the state machine initially transitions to this for cover.
25
00:01:38,130 --> 00:01:42,540
It's a little different since the patrol will always get the position no matter what.
26
00:01:42,570 --> 00:01:49,290
Well, this system might return zero covers and then the air will enter in a locked state, waiting
27
00:01:49,290 --> 00:01:51,990
indefinitely to prevent this as much as possible.
28
00:01:52,000 --> 00:01:57,600
We will use the callback from the timer search new cover and this will ask the cover system from time
29
00:01:57,600 --> 00:01:59,070
to time to get the new cover.
30
00:01:59,070 --> 00:02:02,300
And when found we will transition to move to cover.
31
00:02:02,310 --> 00:02:09,180
If not, we will restart the timer and call again and again because there is one special case when this
32
00:02:09,180 --> 00:02:14,600
situation won't change, if the enemy and also the player don't move at all, nothing will change.
33
00:02:14,610 --> 00:02:20,760
But usually in real life scenarios, the player will most likely move around and the situation on the
34
00:02:20,760 --> 00:02:22,140
battleground will change.
35
00:02:22,140 --> 00:02:27,540
So this means that even if the first time we didn't get the cover, chances are we will be getting one,
36
00:02:27,540 --> 00:02:31,070
the second or the third time when go to cover state is reached.
37
00:02:31,080 --> 00:02:35,490
We know for sure where to go so we can choose an entry to set this to work.
38
00:02:35,520 --> 00:02:39,280
Once the position has been reached, the way state will get triggered.
39
00:02:39,300 --> 00:02:44,070
And lastly here, we need another timer called validate timer.
40
00:02:44,070 --> 00:02:46,860
So how does the timer search for new cover work?
41
00:02:46,860 --> 00:02:53,370
Well, initially on entry happens, we will enter the find cover state and of course the tank mover
42
00:02:53,370 --> 00:02:54,180
needs to stop.
43
00:02:54,300 --> 00:03:00,390
And then we actually call the callback function for the timer to just get it started initially.
44
00:03:00,510 --> 00:03:06,900
And here in our search for new cover timeout, we will try to get a new cover point from the cover system.
45
00:03:07,080 --> 00:03:12,780
If it's different from now, then we set the final state machine to true so that it advances to move
46
00:03:12,780 --> 00:03:13,260
to cover.
47
00:03:13,290 --> 00:03:20,160
If not, then we call the timer search for a new cover again in hopes that in a couple of seconds the
48
00:03:20,160 --> 00:03:21,510
situation will be different.
49
00:03:21,690 --> 00:03:24,720
Right now it's positioned at 1.5 seconds.
50
00:03:24,720 --> 00:03:28,260
So it will try to search for new cover every 1.5 seconds.
51
00:03:28,350 --> 00:03:32,850
Once we get the cover, we can properly transition to the go to cover state.
52
00:03:32,910 --> 00:03:38,790
And here first we need to set up the final state machine, should wait behind cover to false and then
53
00:03:38,790 --> 00:03:41,490
generate the new move path that will give to the tank.
54
00:03:41,490 --> 00:03:45,270
Moving eventually from the current tank position to the cover point.
55
00:03:45,360 --> 00:03:51,150
Once this trigger on finished moving is called, then it means that it should wait behind cover.
56
00:03:51,150 --> 00:03:54,270
And basically this is how it enters the final state.
57
00:03:54,330 --> 00:03:54,810
Wait.
58
00:03:54,930 --> 00:03:59,250
And then the way state on entry is starts the validate cover timer.
59
00:03:59,490 --> 00:04:07,080
What does the validate cover timer do is once it reaches its timeout and then it will get all the targets
60
00:04:07,080 --> 00:04:07,590
in range.
61
00:04:07,590 --> 00:04:15,350
And if one target has a direct line of sight to this particular instance, then this means that we need
62
00:04:15,360 --> 00:04:16,050
a new cover.
63
00:04:16,200 --> 00:04:21,150
And of course we want the cover points to null and then stop the execution of this here.
64
00:04:21,150 --> 00:04:27,750
If not, then will be still running in this state and we will restart the timer to validate the cover
65
00:04:27,750 --> 00:04:30,390
again and again until something happens.
66
00:04:30,390 --> 00:04:35,010
Either it's invalidated or the air enters a completely different state.
67
00:04:35,010 --> 00:04:40,900
And of course when this state is left, so only if it was in the retreat.
68
00:04:40,920 --> 00:04:43,200
Wait, then the timer validate.
69
00:04:43,200 --> 00:04:44,280
Cover needs to stop.
70
00:04:44,280 --> 00:04:47,100
So this is more for the initializing purposes.
71
00:04:47,160 --> 00:04:48,840
And this is the retreat system.
72
00:04:49,200 --> 00:04:50,790
First we search for a cover.
73
00:04:50,820 --> 00:04:53,940
If we don't find one, we keep continuing searching for one.
74
00:04:53,940 --> 00:04:56,610
Once we do find we will go to that cover.
75
00:04:56,760 --> 00:04:59,880
Then we will wait if the cover either is invalidated.
76
00:05:00,110 --> 00:05:01,970
Then we will try to find another one.
77
00:05:01,970 --> 00:05:07,460
Or if the state is no longer necessary, we will exit and go to either patrol or attack.
78
00:05:07,490 --> 00:05:08,870
I hope you like this system.
79
00:05:08,900 --> 00:05:10,790
Leave a comment down below and let me know.
7981
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.