Hello and welcome to technical tuesday,
Today i want to show you how I set up the abilitys in my action RPG Project.
First of all let me introduce you to my AbilityRoot Class.
First the Class has a OnTryCastSpell Event which is the entry point of every ability that wants to be used. Here we already see a few of our needed variables.
Boolean: OnCooldown?, CurrentlyCasted?
MasterCharacter: TopDownCharacter — The Players Pawn Class
What I do is pretty straight forward the Ability should not be on cooldown, not currently be casted, the pawn should not be in the process of casting and the player needs to have the ressources required to cast the Spell.
If all the Conditions are valid to move forward the Spell gets initialized.
The Event InitializeSpellCast sets the CurrentlyCasted = True and calls BeginSkillCast on the Character which sets the currently casted Spell.
Then in OnSpellCast the next variable in my Ability gets used the AnimMontage: SkillAnimation.
First I check if the variable is valid and then i call the macro PlayAnimation which handles disabling the character from moving playing the Montage and setting a delay for when the montage finishes playing:
When the Animation plays its full length without interruption the OnCastCompleted Event gets called and the Spell gets flagged for Cooldown if it has any and is not currently casted.
Then if no cooldown is set the ability is triggered again in recast if a cooldown is set the CooldownVisual gets triggered which handles the visual effect on the SpellIcon and triggers the OnCooldownExpired Event when the cooldown time is finished.
This is the final Event it sets the OnCooldown? variable to false and disables the cooldown image on the Hotkey.
In Addition the AbilityRoot got an empty Event called OnSkillNotify.
This Event gets called in the AnimationBlueprint everytime the animation sends a notify, now if you want to make a new ability you just make a child of AbilityRoot and implement the OnSkillNotify Event with the logic you want.
Let me now show you a example implementation the Gunslinger’s grenade throw:
All I need to implement is the OnSkillNotify Event which Spawns a Actor of the Grenade and gives it a impulse relative to the character and cursor, with static mesh on the grenade and a particle effect the result looks like this:
Stay Tuned for the next technical tuesday, if you have questions or want to see something specific in the next post please let me know in the comments.
Until next Time
Timo