I have been following multiple sources to create my own custom StateMachine in Unity Engine, without any substates. I’ve managed to create a StateMachine that handles every basic, simple requirements of being a character in a video game such as Walk, Run, Crouch, Dodge, Turn and a single basic melee attack combo.
What I aim to do is: Create an Enemy or various player characters such as Mage, Wizard, Tank, Archer etc using this CharacterStateMachine as a Base. I’ve been thinking I should try and employ Polymorphism and Inheritance here to diverge from this base class.
I also wanted to use scriptable objects to keep things clean and stash damage numbers, health values, etc. for different classes/enemies there but that is a question for another post.
I’ll attach my current States and StateMachine for basic visual understanding of states an average player/npc have in common and how many various states I have.
Copy pasting these states or statemachine everytime or rewriting every statescript with a different name doesn’t sound efficient or logical so I reverted back to previous commit. The only way I can think of is deriving from the CharacterStateMachine (name of my StateMachine) and override some methods like Attack (plays a ranged attack animation and deals different damage numbers instead of melee attack damage) but I’m not sure how to do that exactly.
I have not gotten further and when I tried to do research based on my needs, I couldn’t find a specific solution that I can follow along. So here I am.
Thanks for your time and input.
Halil Ibrahim Efe is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.