FSM (Finite State Machines): FSM [Part 1]

https://blog.theknightsofunity.com/finite-state-machine-part-1/

Finite State Machine [Part 1]

Finite state machine may be all the developers had heard at least a few years to start using the Unity game development once.

In the end what is a finite state machine? Well, there are many things to talk about, which is why we have to do at least three parts. Basically, the finite state machine (FSM) is an automated design patterns play a role. Certain behaviors are typically used in AI implementation. Namely: walking, attacking, idling and so on. FSM can be implemented in the NPC, and is most common in the open world RPG.

Here Insert Picture Description

Let FSM deemed supervisor:

Now, the supervisor will check the status of AI. AI will react according to the state. In addition, depending on the type (whether it is flying type, the type of ground or swim type) AI's, AI will execute the action. In this case, FSM told AI that he is in a "state patrol" and told AI 'walk from A to B ". Unless the state changes, otherwise the AI ​​will only go from A to B.

Here Insert Picture Description

To change the status, we must first have a condition. On the left, AI saw the players and told the supervisor. Now, the supervisor will change the status of AI, and began to attack.
Here Insert Picture Description
Also, since the player is not within the line of sight, so AI resumed patrols.

As can be seen from the production of these bad drawing, each state change before other state has its own conditions.

Let's look at the following chart.

Here Insert Picture Description

This is normal AI state diagram.Red lineIndicates the status change requiredThe condition is false. The map is very simple. If the AI ​​reaches its destination, it will be in an idle state, and vice versa. If he sees an enemy, it will begin to attack. FSM can now handle all transitions between states, and to help the AI ​​performing the operation state is available.

Now, let's break it down FSM system.

The main FSM system - it will be to control and check the conditions of AI state between the state people. FSM will include all primary status, and the processing from

  • FSM action event calls.
  • State of the FSM - determine the current state of AI and disposed on AI include all operations.
  • FSM action - action that will be AI AI will be executed in a particular state.

How will we do now? Let's put everything mapped out.

Here Insert Picture Description

This will be the circulation of our FSM. First, we initialize the FSM, created the state, and all of them create an action map together. After mapping them, we will now start the FSM and indicates the status of AI will begin. Now, AI will be changed to a particular state, FSM will initialize action, update it until the operation is completed, and completed action sends an event indication. Finally, FSM will go back and change the status.

AnotherIt will cause the state to change thingsYesWhen an event is called outside the AI ​​logic. As we create commander and told all the soldiers as stops moving.

So far, the first part of our FSM tutorial is over. I hope I have shown you a good explanation of FSM. If you still do not know, maybe you need to see all of the actual operation, and personally scan all content. This is what I learned.

In the next section, we will first discuss some simple FSM achieve real again, and we'll write from scratch the entire FSM engine script!

Published 16 original articles · won praise 2 · Views 467

Guess you like

Origin blog.csdn.net/Heroan1123/article/details/104038608