Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

"Swing and a Miss" - Luke Cardelli | 19 October 2023

The Problem:

Unlike a first person shooter, creating a melee system and handling the damage out is rather tricky situation. With shooters, you have the benefit of doing a line trace, checking to see if it hit anything, and then proceeding to apply the appropriate amount of damage. Melee combat is a little trickier as you have to do multiple checks to account for the duration of the swing.

With the initial damage system implementation, we opted to do a sphere collider that spawns every 0.01 seconds around the blade during a swing animation and check whether the sphere collided with a pawn during a portion of the swing. Upon collision, we would call a apply damage function that would then reduce the pawns health. This worked well enough, but there was an issue wherein there were multiple collisions that occurred throughout the duration of the swing resulting in numerous damage calls to occur.

The initial fix was to lower the damage out of the player and enemy to accommodate the numerous swings. This was a hacky fix as it did reduce the damage out, but it then made the damage out inconsistent. We tried increasing the amount of time between swings but this then created a new issue wherein gaps would be created between checks causing the player and enemies to have miss hits. We need a solution that accomplished two things: 1) reliably deal the amount of damage one would expect to occur on overlap 2) ensure that on a collision only a single call to apply damage was made.


 <Reference Image - Green lines indicate every time the player was struck / when the apply damage was called>

The Solution:

The solution was a relatively easy one. After some brainstorming, I had determined that I needed to store the collider information post each collision. I needed to know what the player or enemy hit and then check whether or not they have already hit that object during their swing. What I did was create an array that would store information to pertaining to all pawns that were hit during the swing and then check as to whether or not they had already been hit. If so, ignore that actor and forgo calling the damage function. If not, then apply damage.

We added state notifies to the animation blue print to know when to begin adding objects to the array and when to empty the array. This then would allow for the implementation of combos. All and all, a relatively simply problem with and an easy solution.



<Reference image of the addition of an array to check for pawns to ignore>

Support this post

Did you like this post? Tell us

Leave a comment

Log in with your itch.io account to leave a comment.