Making Any Character Fight! A Dynamic Approach To Character & Ability Classes
Published:
So, after watching a whole bunch of videos on Dark Souls bosses duking it out using mods, I began to think about how I would implement a similar system. In the beginning I asked, “Why even allow Bosses in the game to fight each other?”, since they never used this in the game.
Example from Dark Souls 3 on this
Now after studying and practicing concepts with classes, objects, and inheritance, I managed to develop a similar system with Potato Mage in making ALL objects dynamic, so any Character can attack any other Character in the game as long as they’re on a “different faction”. The hitboxes spawned by each character simply share that character’s faction, no relationship between each object is necessary, they’re completely independent from incapsulation. Then all I have to do is set each character’s target, make sure they’re on different factions, and watch them brawl! I could’ve also created an aggro system too based on whoever is attacking/taking damage, but that’s more for later.
My take on it in Potato Mage
- The Character Class Structure
- Creating the whole class structure was simple enough, you basically just have a Base Character class that can generally be used for any character to inherit from, this includes: the Player, Enemies, NPC’s, etc. Then this BaseCharacter class would then have general functions for: taking damage, attacking/doing actions, etc. Each subclass would then fill in their own ways in which they’d react to taking damage and stuff like that, for things like Animations.
- (Characters would basically handle their reactions to getting hit by hitboxes. Which honestly I might refactor again to make its own component just so more things can be damaged easily just by adding this component class to them, and to reduce the clutter since the Overlap functions are kind of big.)
- The Ability Class And Hitbox Component
- So when designing the structure of the game I wanted abilities/attacks to scale off of a character’s stats and also use their faction. So whenenver an object that inherits from an Ability is spawned, it basically just has a pointer to its Character ‘Owner’ then scales the object’s damage accordingly to the character’s stats. Aaaand that’s all it really does.
- Each different Ability would also have a Hitbox Component slapped onto them so they can cause characters to react and take damage…or restore health too. This Hitbox Component literally has no code or references within it, this hitbox is just a capsule that ‘characters will want to run from in order to save themselves!’. The damage of it is also stored inside of it. The Ability Owner Class changes this damage value in the hitbox based on a Character’s stats. (NOTE: The hitbox doesn’t even reference their Ability Owner, it stores its Owner as an Actor Class).
- And so from this Abilities are only tied to their Owner Characters, and the Ability Classes spawn a modified hitbox based on their Character. From this, Hitboxes can also be spawned on their own too, they’re independent in that regard for things like “Environmental Hazards” which don’t have a character, so they don’t need to be an ability. As a bonus I made a HitboxEffectInterface which could be added to anything with a hitbox, this interface has a function that gets called when the hitbox hits something, then it would cause its Owner to do something (Like spawning an effect). This is fantastic for handling things in Blueprints when I want to design things.
A Small Exhibition Of Bosses Fighting Eachother
- Some Troubles Faced
- The toughest part when looking at this system was that it was super easy to fall into traps with development in making objects rely on specific scenarios instead of allowing any scenario to take place. I also watched a lot of Youtube tutorials on things like “AI systems in Unreal”, and usually they’d target specific things like the player directly in their code, which isn’t a good approach obviously. In the beginning, I also hardcoded enemy abilities to target the player. I just think using direct pointers to objects or to specific classes is super easy to fall into, and it should be avoided as MUCH as possible, keep things GENERAL. This is also huge in memory management, as you could fall into referencing a class that’s tied to a costly asset. After all of that, I had to refactor everything and now they can target/attack any character in the game, and everything uses general references to base classes.