Skip to content

An example of finite state machines being implemented in a 2D Unity game for non playable character behaviour

License

Notifications You must be signed in to change notification settings

theGusPassos/unity-finite-state-machine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

unity-finite-state-machine

An example of finite state machines being implemented in a 2D Unity game

Unity Finite State Machine Demo

The following sample has a playable character and an character controlled by the finite state machine. The NPC will patrol until the playable character is within his field of view, and will stop following when the character is out his field of view.

References

Development setup

Just edit the project in Unity 2019.2.0f1 +

Development Flow

How add a new character with different behaviour

  • Create a new class that extends the FSM base class, this will be the FSM class for the new character
  • Create new State classes if the basic ones don't have the expected behaviour
  • Create new Transition classes if the basic ones don't have the expected behaviour
  • In the FSM class for the new character, override the SetupStates
  • Instantiate the required states and transtions, use serialized fields to ease the config setup in unity engine
  • Use the created states and setup its transtions by calling SetTransitions
  • Assign the starting state
  • Create an awareness object if your states and transtions use one
  • Call SetAwareness to set it in the base class

Contributing

  1. Fork it
  2. Create your feature branch
  3. Push to the branch
  4. Create a new pull request

License

License

About

An example of finite state machines being implemented in a 2D Unity game for non playable character behaviour

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages