top of page
Writer's pictureHolly Boyle

Hit Detection & Health Component


Now that we had our main sword weapon equippable by the player, the next step was to develop a system for detecting when an actor has been hit by it.

We were likely going to have many different types of objects be damageable by the player's weapons, so I created a general "Weapon Hit" blueprint interface to handle this.


To start testing this feature, I set up a simple target dummy actor using a cylinder static mesh. I created a collision channel for weapons, and set the dummy actor to overlap it.


Health Component

For implementing the target dummy's health, I ended up taking a different approach than I was used to. Ordinarily I would just create some variables and functions in the actor and use call them when needed. However, I thought about the fact that there would be many different types of actors, not just regular enemies, that might need their own health values. If I went about this the way I was used to, I'd end up having to copy and reimplement the same code quite a lot.


Instead, I decided to create an 'Actor Component' that would contain the basic variables and functions required to track any object's health stat. This component can be added to any actor that requires it, and their own events can be bound to the component's "Health Reached Zero" event.


Besides saving time, this approach also meant that I could make one Health-bar widget that could be used by any actor. All it requires to work is a reference to the Health component, rather than having each actor track and update the widget with their own variables.



With the Health component and widget created, I quickly set up the target dummy's blueprint to decrement health when overlapped by the sword weapon.


At this point, the sword only dealt damage upon first entering the dummy's collision, and wouldn't deal damage again until it had left. This felt clunky and also made the optimal strategy to be shaking the sword back and forth at the edge of an enemy's collision, which was something the team explicitly wanted to avoid.


Swing Detection

To try and solve this, I started experimenting with detecting the sword's velocity when colliding with enemies, to make sure the player was actually performing a swinging motion.

To keep the blueprint better organized, and in case I needed to reuse the code for any other objects, I put together another Actor Component that would keep track of this.



Within its own tick event, the component compares the sword's position between frames, determining if its velocity meets the required threshold to be considered a swing. It also makes sure the sword has been travelling at the required speed for a certain duration before it can be considered in a swinging state.


After a lot of testing, I found some velocity threshold settings that I felt worked well. The only issue was, there was very little feedback to the player to properly indicate if they were swinging the sword fast enough or not for a hit to register.


Sword Trail Effect

To help the player see when their sword was in its 'swinging' state, I wanted there to be some form of visual indicator. Something I had already planned to add to the sword at some point was a trail effect, so I decided to use this as the indicator.





2 views0 comments

Recent Posts

See All

Comments


bottom of page