I have been on fire adding functionality to my project. Loving it. So I am on to adding a “Composure” vital stat… Like a few other games, notably Outward and Souls games… If you block you still lose some of it… You get knocked back(and down for me) if you run out… It regenerates very quickly out of combat and pretty much instantly after you get knocked down. Composure.cs is one of my most elegant scripts I’ve written on my own.
However… In order for it to work I need to know if an enemy or player is in combat. And to keep Composure universal between the two types (player and enemy) I want the statemachines to call and tell it when combat is or isn’t happening rather than having an if block to check a PSM vs ESM. I think I landed on some decent logic for telling in combat. For the player it (will be) a list of enemies that are either attacking or in chasing state that fall of after X amount of seconds… But what I am testing first… Is flagging when an enemy takes damage, is chasing, or is attacking. Then after 5 seconds of not doing any of those things it will be out of combat.
Long story short… I am trying to keep track of the enemy’s last time they made a combat action inside EnemyStateMachine so it can be universal across all their states. However… It seems like ANYTHING in Update in the main StateMachines makes the character frozen. I tested this by simply throwing a debug.log in the player state machine… Sure enough… can’t move…
Am I total noob? Why is this the case? And bonus points if you can suggest a place that I try this logic(Though I suppose a general use Combat.cs slapped on to everyone and interfaces with the appropriate SM’s would be fine). I do just about EVERY main action from the PSM such as jump, dodge, etc because I want them available in any state (and there is a hefty IsPerformingAction() check I do to stop you from dodging in mid air for example). I also chose this route because I want to be able to interrupt animations to block or dodge anyway. These all work great but don’t need an update tick. Sigh.
Yeah I made an EnemyCombat.cs for tracking combat conditions and I believe it is working just fine. Got my Composure working with a rudimentary bar slapped into the HealthBar we made in the RPG course that is now VitalsBar: