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
0 In this example, we will have three different states: the idle state, the move state, and the fire 1
state. 2
These are basically just some scripts with a little code. 3
They're nothing special. 4
But of course you can imagine that this is an AI because it can be 5
an actual AI here. Every state will be connected with each other and will trigger transitions when 6
specific conditions are met. 7
Let's configure the finite state machine example first. 8
This will be the main screen which currently has two buttons. 9
Is moving button and is firing button. 10
Basically what they'll do is have a special signal. 11
That this called in this debug script and this debug script. 12
What it does it has two signals from is moving button and is firing button and it was set up two states 13
and will set up inside the custom finite state machine that we created. The database with the is_moving or 14
is_firing and will also reflect this in the button text itself. 15
Also, we need to show the current state in a label. 16
So if we go back, the current state will be visible in this label to be able to properly debug it. 17
Now let's go back a little to the idle state because we need to make some changes here because we will 18
have some connections between idle state, move state and fire state. 19
If the finite state machine... 20
By the way, in this implementation, in the check conditions, we will create the transitions for various 21
states. 22
So we need to get the value and is moving. 23
Be mindful that this value is actually set in this debug script. 24
So is_moving. 25
It needs to be the same. 26
I can just copy paste it to make sure is the same. 27
Otherwise what I recommend you to do is create a globals file. 28
You can do that by using a singleton in Godot and basically create a variable that has this string 29
and use that variable instead to remove the hardcoding part. 30
Because by just missing one character here, then it won't work anymore. 31
This is a pro tip basically. 32
So get value is_moving. 33
And of course this is true. 34
Then we need to change the state to the move state. 35
How is the move state called? 36
Well, it's actually the same name as here. 37
And, if you remember from the implementation, we get every state from the children. 38
We create the dictionary where we keep our values. 39
So based on the name actually written here, we actually get the state as well. 40
So this is how we go to the move state. 41
And now, of course, we don't want to continue this because we already changed the finite state machine 42
to the move state. 43
But if it was not moving, then it might be a possibility for it to be shooting or is_firing. 44
And if that's the case, then we need to change it. 45
FireState. 46
And by changing to the fire state, then of course, this is a new state. 47
And in the move state as well as in the fire state, we see very similar code, but we just check for 48
the values in the other direction. 49
Just be mindful that some changes here are really important. 50
So as you can see in the move state, it's a little different. 51
The if statements are embedded as well as in the fire state. 52
This is important to prevent unusual transitions in the state machine. 53
Before we can run this, I need to set up the entry state in the custom finite state machine. 54
And of course I want it to be IdleState. 55
So the entry state will be running. By the way, if we run the state machine about this, it'll crash. 56
So make sure to actually put this here. 57
If we run this, then of course, the current state is idle state and we entered the idle state. 58
If the enemy is moving, then the variable is_moving will be set up. 59
In this case, I'm just going to set it up by pressing the button. 60
But as you can see, we exited the idle state and we entered the move state. 61
And the current state is of course, the move state. 62
If I put in the firing. 63
As you can see here, the moves state is still going because of the way conditions are created. 64
So it will go to firing only if I disable is_moving. 65
And basically what it does here, it goes back to idle and then checks: is firing online? 66
And as you can see here in the moving so exited move state. Entered idle state exited idle state 67
and entered fire state. 68
And this is how we end up in the fire state. 69
Be careful how you create your transitions because this will affect your whole logic of the finite state 70
machine. 71
Basically, this is all about finite state machines. 72
Now let's find out in the next module how to get an AI from a position A to a position B using pathfinding.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.