RPG Development - Attack Skill Class Implementation

Note: I was a bit confused as to where this thread should go, and realized after I posted it that this may indeed the wrong forum section to be posting it in. That said, I see no options for moving or deleting it, so I’ll have to rely on a mod to do that, if necessary. My apologies if that’s the case.

I’m finding myself caught in one of those situations where the number of options available to me is a bit overwhelming, so I thought perhaps I’d consult with the advice of the veterans here.

I purchased the Action RPG Kit from the AssetStore a few weeks back and while I find the majority of the scripts useful (at least as an example, if not for any sort of practical application), I was a bit disappointed with the “combat skill” system. It’s just a simple class collection of an attack prefab (which is collider used for the hit area along with damage details and such), a mana cost, and a legacy animation reference on top of a few details that really don’t effect the mechanics at all. That’s fine if “spells” and simple hits are really the full extent of your skill system, but for wanting to chain together different animations, hits, and effects into one object, it doesn’t help at all. That’s fine- this post is not a review or criticism of the package (which I found well worth its value as a basic “guide”), but in needing to implement my own solution from scratch I’m hitting a brick wall of indecision (or perhaps just lack of confidence, or lack of social interaction…).

My requirements are as follows:

  • It must utilize Mecanim, not the legacy system.
  • It must be able to handle a variable number of sequenced animations, hits, and visual effects spread throughout the life of the skill (start animation, show effect at .4 seconds after start, another effect at .6 seconds after start, “hit” enemies at .6 seconds after start, for example).
  • I can chain together animations in Mecanim in a SubStateMachine easily enough to form the animation sequence for a single “skill”, but the skill system itself has be aware of those states, able to control the state changes (or at least respond to the changes), and do so in a generic way that does not require different coroutines for different skills.
  • Skills do not necessarily have to be universally usable on any PC, NPC, or Enemy in the game, but the skill system should be the same for each even though the skill database is not.

After careful consideration, I’ve come to the conclusion that I should use a class that holds data for the skill as a whole (like the data you’d see on a “skill details” screen), like the mana cost, the attack type (physical or magical), the element (if any), the name and description of the skill, etc…

There should also be a “Skill Stage” class, which has settings for each individual stage in a stage-queue, each with data on whether the effect (if there is an effect for that stage) should be fired at the beginning or end of the stage, the same for a “hit” (if a “hit” for that stage exists), and whether there should be a pause at the end (looped animation or frozen?) for X number of seconds until the next stage fires. There should be a list of these stages for every skill.

The final piece of the puzzle lies in the StateBehaviour scripts for the skills. I could have it so that the progress through a skill’s SubStateMachine is tracked and reported to the skill manager script, that each animation “stage” uses the same NextStage trigger to progress (triggered by the skill manager), or some such thing. My experience using Mecanim is limited, so I’m really uncertain about this aspect.

So, on to my question at last- I’m really hoping you veterans out there with a better grasp of RPG mechanics will know if there’s some unseen factor I’m missing here, whether this solution seems like a solid approach or flawed, am I reinventing the wheel when an identical system already exists out there that maybe I just haven’t happened upon yet, etc…

Really any thoughts or advice would be greatly appreciated, even not relating directly to the question at hand. I’ve been coding for months now on one project or another with almost no interaction with others in regards to my projects, and I’m honestly feeling like maybe I just need a little bit of encouragement, if any can be had, or maybe just some basic human contact (it’s dark down in this hole, and they only feed me once a day).

are you aware of the Animation Events? essentially calling functions at set times in the animation, predefined or can be added/edited/removed via script if needs be

http://docs.unity3d.com/Manual/animeditor-AnimationEvents.html

Thanks for the reply!

I am aware of AnimationEvents, and using the deprecated system they worked fine while when using Mecanim they screw up pretty much 100% of the time. Any animation events placed at the end of an animation usually won’t fire at all, due to being transitioned out a few frames early (unless I’m VERY careful about the transition end-timer in Mecanim). The ones that are set early enough in the animation to not be effected by that will consistently fire twice (simultaneously, in the same frame), because I make it standard practice to have several versions of the same animation in a state machine with parameters to change animation speed, mirroring, etc… Also, there’s no reason that I shouldn’t be able to have different events throughout the animation depending on the type of object using the animation asset, which is something that’s easy to manage using StateMachineBehaviours but difficult to manage when you’re attaching the event to the animation clip itself.

I long-ago replaced the use of animation events by using StateMachineBehaviour scripts with “total animation time passed” percentage-based triggers that fire in OnStateUpdate (fire “event 1” delegate when 80% of animation has played, for instance). This mimics the bahaviour of the AnimationEvents without the side-effects, since OnStateExit can be used to invoke a “finished animation” delegate, and since the “events” are tied to the state machine as a whole rather than a specific animation within it, it won’t be called twice simultaneously in a single frame when the timer is reached. Moreover, the delegates/timers/number of events can be completely different for different objects (or different types of objects) re-using the same animation assets.

UPDATE (missed this part):
“…or can be added/edited/removed via script…”

I should note that I’ve actually never seen this (I always edited the clip asset itself to place/remove Animation Events). The only issue this would potentially solve, however, is having different animation event sets on an animation clip for different objects or types of objects. That’s already solved with the StateMachineBehaviour script alternative though, and it doesn’t fix any of the other problems with using the old method. shrugs