Yeah. Due to the derivative nature of my project (if you look at my other post on previous course related to how I’m making a Metroidvania style game instead of a pure Diablo style game), I had to implement a bit more complexity in the PlayerController.cs than shown in the course and, with that, I basically fused quite a few part with my own variant because it was just simpler.
Since I’m already building a database of the weapon that includes the possibility of different animations for different weapons under a same type, I’m already building a database of available animations anyway so adding an array of floats for timing the Hit(); is not that much of a trouble for me.
The way I implemented the state in the Animator is, in my opinion, a clever one.
There’s a layer prior to the combat animations involving if the player has a weapon out or not and if not, it pull out the weapon as the combat starts. I won’t cover it here, but let’s just say that, in my project, you can have a weapon out or, in some cases, sheathed.
When it comes to combat animation, my animator only has 5 animation states for combat and I’m using the AnimatorOverrideController method to replace those 5 animations with the various animations based on my weapon database that includes an array of a class I created that hold the reference to an animation clip, the hit timing, the radius & range of the attack, if applicable, so that certain attack animation can, for example, hit more than just the target. I only have to override the Animator controller once when the character (player or AI) is instantiated and, then update it whenever the player change equipment.
The cycle between the attack is, then, handled by simply setting up an integer in the animator (I called it “Combo Length”) which allows the attacks animation states (0 to 4) to transition from one to another while checking if the next animation in the combo is higher than that integer (if it is, then the transition moves back to animation state 0 and skips the remaining states).