Designing A Souls-like Block Mechanic In UE4 | Tech Discussion
In this tech discussion I'll describe how I went about adding a block mechanic in Mythicism.
In a previous blog post I explained how our combat was designed. To summarize, there is an interface IDamageable containing TakeDamage behavior which the player and enemies implement:
Then, when a weapon overlaps with an IDamageable, it call that IDamageable's TakeDamage method, passing in the amount of damage the weapon wants to deal:
Lastly, so that the weapons only deal damage during attack animations, the weapons are "activated" and "deactivated" using an animation notify state that calls these methods:
Now for the block mechanic. As Mythicism is a Souls-like game, we wanted for our block mechanic to transfer a percentage of health damage (depending on the efficiency of the shield) to stamina damage and cause the player to stagger and break their stance if all of their stamina gets exhausted. We also wanted for the shield to only be able block attacks from the front and not from behind. Now this last feature, only being able to block attacks from the front, posed a problem for me that would affect the way I went about implementing all the other features of the mechanic. As you can see from our combat system, there is currently no way of knowing where attacks come from; the player simply receives a call to TakeDamage and takes damage.
In order to solve this problem, I thought about how shields actually work in real life. Similar to how in real life, it is the weapon that deals damage to the person being hit by that weapon (and so I designated the in-game weapons with the responsibility of "dealing damage" by calling TakeDamage on the IDamageable they hit), the shield receives damage on behalf of the person holding it (costing them stamina as well for the exertion). Therefore, I let the shields in the game also implement IDamageable and be hit by the weapons instead of the player. When a shield receives a call to TakeDamage, it then calculates how much health damage to defer to stamina, and "passes along" those damages to the owner of the shield.
Then if the shield is positioned in front of the player, the shield should be hit first and take damage on behalf of the player.
But wait! There is a problem here. Since weapons overlap with the shield and the player, after passing through the shield, the weapon may still hit the player and deal double damage to them.
To avoid this, I used the DisableDealingDamage method mentioned before to disable the weapon after it hits the shield, thus protecting the player from additional hits.
The last step to making this shield mechanic, excluding all the animation programming and input handling, is to be able to enable and disable the shield when blocking starts/ends, just like the weapons can be enabled and disabled when attacking starts/ends.
With all these parts in place you will have a working block mechanic and input binding and animation blending can be customized as desired.
Author: Reilly da Silva
Get Mythicism
Mythicism
Status | In development |
Author | Arcane Studios |
Genre | Action |
Tags | 3D, Action-Adventure, Dungeon Crawler, Fantasy, Singleplayer, Third Person |
More posts
- DOT Particle Effect Not Working In Release Build | Tech DiscussionJun 24, 2022
- Tech Discussion | Boss Post MortemJun 23, 2022
- Ranged Enemy Aiming Problem | Tech DiscussionJun 17, 2022
- A Problem With Blade Trails | Tech DiscussionJun 10, 2022
- Tech Discussion | Boss BehaviorJun 10, 2022
- How To Edit Animation Sequences (Additive Layer Tracks) In UE4 | Tech DiscussionJun 03, 2022
- Tech Discussion | Altar System and Player levelingMay 23, 2022
- Tech Discussion | Save SystemMay 23, 2022
- Adding Varied Footstep Sounds | Tech DiscussionMay 15, 2022
Leave a comment
Log in with itch.io to leave a comment.