Player State Machine / State Pattern:
Grid Ninja » Devlog
This helped me maintain the player's different states inside the game.
So basically my character has 3 states as of now and there are as follows.
- Moving State: During this state, the character automatically moves toward its current direction.
- Changing Direction State: The player will switch to this state, whenever the player tries to change the direction according to the input given, then once the direction change finishes it will switch back to "Moving State".
- Player Stop State: This state works when we want to stop the player.
Why State Machine?
- Each state's code is self-contained.
- Allows us to modify the behavior Independently.
- Changes to one state will not impact other states.
- We can Implement the state pattern with a Finite State Machine.
Finite State Machine:
- There are a limited number of states in a Finite State Machine. Only limited to the number of states we program.
- The player can be in one state at a time.
How to Create:
For creating a State Machine we have to follow 3 components.
- Context
- Abstract State
- Concrete Stat
To know more about these components check the diagram attached.
Basic Code Example: PlayerStateMachineBasicCodeExample
Grid Ninja
Player expand territory and eliminate opponent. Player with big territory wins.
Status | In development |
Author | Goutamraj |
Genre | Strategy |
Tags | Indie, Multiplayer, Ninja, Pixel Art, Top-Down, Two Player, Unity |
Languages | English |
More posts
- AWS EC2 Dedicated Server deployment12 days ago
- Detection of a perfect point to start Flood fill: The Working SolutionOct 06, 2024
- Detection of a perfect point to start Flood fill: The Failed SolutionOct 06, 2024
- Fill Player Territory (Using Flood Fill)Oct 01, 2024
- The Player Controller and Input SystemSep 28, 2024
- EnvironmentSep 25, 2024
Leave a comment
Log in with itch.io to leave a comment.