Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Let's find out about the retreat functionality.
One of the three states of our agent.
The retreat feature consists of a state machine definition and the state code to make it work.
It gets triggered when the agent's HP drops below a certain value that can be customized for different
behaviors.
Let's start by looking at our state machine.
So this is the first level.
We need to double click into retreat and here to find the following three states.
First, when entered the retreat, functionality will try to find a valid cover.
If a cover was found, then it will go there to that cover and then it will wait for a certain period
in the cover if the cover is invalidated for some reason.
For example, the player moves and has a direct line of sight to the enemy.
Then the cover will get invalidated.
It will try to find a new cover.
If it is false, then this means that this state is no longer available and the air can move to attack
or patrol state.
Let's look now at the code and how everything is put together.
After the initialization step of various objects, we also need to connect the tank mover so that we
have unfinished moving.
But we also have two important timers search for new cover timer and validate cover timer.
So what do they do?
If you checked the patrol state, you probably are aware that when the patrolling gets called on entry,
the new patrol position is picked and the mover is set to go there.
Their own entry happens only once when the state machine initially transitions to this for cover.
It's a little different since the patrol will always get the position no matter what.
Well, this system might return zero covers and then the air will enter in a locked state, waiting
indefinitely to prevent this as much as possible.
We will use the callback from the timer search new cover and this will ask the cover system from time
to time to get the new cover.
And when found we will transition to move to cover.
If not, we will restart the timer and call again and again because there is one special case when this
situation won't change, if the enemy and also the player don't move at all, nothing will change.
But usually in real life scenarios, the player will most likely move around and the situation on the
battleground will change.
So this means that even if the first time we didn't get the cover, chances are we will be getting one,
the second or the third time when go to cover state is reached.
We know for sure where to go so we can choose an entry to set this to work.
Once the position has been reached, the way state will get triggered.
And lastly here, we need another timer called validate timer.
So how does the timer search for new cover work?
Well, initially on entry happens, we will enter the find cover state and of course the tank mover
needs to stop.
And then we actually call the callback function for the timer to just get it started initially.
And here in our search for new cover timeout, we will try to get a new cover point from the cover system.
If it's different from now, then we set the final state machine to true so that it advances to move
to cover.
If not, then we call the timer search for a new cover again in hopes that in a couple of seconds the
situation will be different.
Right now it's positioned at 1.5 seconds.
So it will try to search for new cover every 1.5 seconds.
Once we get the cover, we can properly transition to the go to cover state.
And here first we need to set up the final state machine, should wait behind cover to false and then
generate the new move path that will give to the tank.
Moving eventually from the current tank position to the cover point.
Once this trigger on finished moving is called, then it means that it should wait behind cover.
And basically this is how it enters the final state.
Wait.
And then the way state on entry is starts the validate cover timer.
What does the validate cover timer do is once it reaches its timeout and then it will get all the targets
in range.
And if one target has a direct line of sight to this particular instance, then this means that we need
a new cover.
And of course we want the cover points to null and then stop the execution of this here.
If not, then will be still running in this state and we will restart the timer to validate the cover
again and again until something happens.
Either it's invalidated or the air enters a completely different state.
And of course when this state is left, so only if it was in the retreat.
Wait, then the timer validate.
Cover needs to stop.
So this is more for the initializing purposes.
And this is the retreat system.
First we search for a cover.
If we don't find one, we keep continuing searching for one.
Once we do find we will go to that cover.
Then we will wait if the cover either is invalidated.
Then we will try to find another one.
Or if the state is no longer necessary, we will exit and go to either patrol or attack.
I hope you like this system.
Leave a comment down below and let me know.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.