Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:00,030 --> 00:00:01,800
What are finite state machines?
1
2
00:00:02,220 --> 00:00:08,490
Well, a finite state machine or, for short, FSM is a collection of states and transitions.
2
3
00:00:08,520 --> 00:00:16,890
The states represent the actions that an AI agent can take. For example: fire, run, patrol, and so on, so
3
4
00:00:16,890 --> 00:00:17,310
forth.
4
5
00:00:17,580 --> 00:00:24,510
And the transitions are the links between these actions that tells when the AI should change its current
5
6
00:00:24,540 --> 00:00:25,020
state.
6
7
00:00:25,050 --> 00:00:31,320
For example, if the AI was patrolling and it encounters a player, then the state should change from
7
8
00:00:31,320 --> 00:00:38,610
patrol to attack so that AI can properly play the animation, fire the projectile and face and run
8
9
00:00:38,610 --> 00:00:39,630
towards the enemy.
9
10
00:00:39,840 --> 00:00:45,480
This is one example, but finite state machines is one of the most common ways to implement AI
10
11
00:00:45,480 --> 00:00:46,260
in games.
11
12
00:00:46,380 --> 00:00:51,990
Behind the scenes, an FSM is basically a graph and if you don't know what the graph is, then you should
12
13
00:00:51,990 --> 00:00:54,540
definitely check the bonus section, the data structures.
13
14
00:00:54,570 --> 00:01:02,490
What it does is basically these nodes represent the states and the transitions represent the edges between
14
15
00:01:02,490 --> 00:01:02,790
them.
15
16
00:01:02,820 --> 00:01:07,470
Let's now look at the pros and cons of using a finite state machine.
16
17
00:01:07,710 --> 00:01:13,830
Well, one of the most important pros is the fact that it's very easy to use and understand.
17
18
00:01:13,860 --> 00:01:15,780
You basically create the states.
18
19
00:01:15,870 --> 00:01:17,370
You name them and you use them.
19
20
00:01:17,700 --> 00:01:20,220
You connect them via transitions.
20
21
00:01:20,220 --> 00:01:21,600
And basically, this is it.
21
22
00:01:22,110 --> 00:01:26,560
And of course, because of its simplicity, that means that it's very fast.
22
23
00:01:26,580 --> 00:01:33,720
So if you have a lot of AI instances, for example: 1000, then a finite state machine would do good
23
24
00:01:33,720 --> 00:01:36,030
because it doesn't require so much processing power.
24
25
00:01:36,120 --> 00:01:38,460
What are the cons of a finite state machine?
25
26
00:01:38,880 --> 00:01:44,790
Well, the first one that it might get out of hand quickly if you had more states, more transitions,
26
27
00:01:44,790 --> 00:01:50,250
you interconnect them with each other, then you might end up with a spaghetti of something that it's
27
28
00:01:50,490 --> 00:01:51,390
hard to maintain.
28
29
00:01:51,720 --> 00:01:58,140
And it's also hard to reuse because you cannot just take parts out of it because they are tightly connected
29
30
00:01:58,140 --> 00:01:58,980
with each other.
30
31
00:01:59,340 --> 00:02:04,650
But with all of these cons, I still believe it's a powerful system and it's used in modern games.
31
32
00:02:04,890 --> 00:02:11,730
There are ways to mitigate all of these risks by implementing something called hierarchical state machines.
32
33
00:02:12,210 --> 00:02:18,770
And the good news is that in the final project that we will have in this course, we actually have a
33
34
00:02:18,780 --> 00:02:20,910
hierarchical finite state machine.
34
35
00:02:21,180 --> 00:02:28,920
Basically what it means is that the groups states together in bigger states to avoid having too many
35
36
00:02:29,250 --> 00:02:30,780
redundant transitions.
36
37
00:02:31,320 --> 00:02:37,020
But you'll find out more in the later project. Now that you know what the final state machine is
37
38
00:02:37,110 --> 00:02:40,560
let's find out how you can implement one yourself in Godot.
4042
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.