Hollow Knight Inspired Combat with the Hazard Recipe


Hollow Knight's combat system is simple enough in terms of its core features. What really turns it interesting are its strategy elements, especially in Silksong: charms, crests, and tools help you customize the character to fit your playstyle or strategy better to overcome a given challenge.

I want to introduce these strategy elements with the Equipment recipe that we are trying to fund with the Hollow Bot Update funding campaign. Check it out through the link below.

The Hollow Bot Update Funding Campaign

But to implement the action elements of this simple yet charming combat system, we can use our Hazard recipe, which I’m going to update it and rename as Combat System after the update. Before we dive into action, let’s analyze Hollow Knight and Silksong combat features.

Analyzing Hollow Knight Combat

What’s interesting about Hollow Knight and Silksong’s combat system is its simplicity. You don’t have combos or special actions (like an special attack triggered by a combination of buttons in sequence, like a Hadouken). Every combat action is assigned to a button in the controller.

Please, skip to 00:13:33

Team Cherry layered on top of that a multidirectional melee combat. That means that the main characters’ (Knight or Hornet) look direction will change the position of the attack’s hit box. Check it out, this player is figuring out he can perform an upper slash.

Please, skip to 00:31:20

📝 Design Note:
It took a while for this player to figure that out and he was only able to understand this mechanic once faced with a particular type of enemy, a flyer. Skip to 00:32:40 to see this "aha" moment.

Flyers add a new dimension to combat and movement. Prior to that, this player used to jump to get at the same level as other flyers and hit them horizontally. But at this moment, the layout of the map constrains the player’s horizontal movement, forcing them to think out of the box, leading them to try out new strategies and figuring out they have a vertical attack.

This is the main purpose of using flyers, to add new dimensions to combat and movement. I’m thinking about writing a book about 10 Enemies Archetypes and how to implement them in your game, let me know in the comments if you’re interested.

Well, with this in mind, it’s worth talking about spells as well, on a side note. Spells are a sub-system of the combat system, known as the magic system, so we are going to get into them in another post. Let’s see how we can use the Hazard recipe to implement a melee combat system like Hollow Knight’s.

Implementing the Combat System

Every combat system is made up of two components. People usually ignore the second one, because for some reason they use the name for both component. But in our system, we have:

  • The HitArea2D, the active component of the system that searches for the passive component and passes hit data to it. This is commonly known as a Hit Box.
  • The HurtArea2D, the passive component of the system which provides a method for the HitArea2D to inject hit data on it and process the hit data, outputting the final damage dealt.

Since you already have the Hazard recipe instructions, let’s build on top of it and focus on how to use it for melee combat. For those who don’t have the Platformer Essentials Cookbook yet, first of all: why not, duh? Secondly, you can download the system using the link below:

Download Ludonaut’s Combat System

The way I’m going to approach this system is similar to what I’m doing on my top-down shooter, so we are also going to use my Weapon System as well. The whole idea of my weapon system is that a weapon is a “Hit Spawner”, or in the case of top-down shooters, a Bullet Spawner.

Since Bullets are nothing but moving hit boxes, we can “generalize” the system to instance any kind of hit box. In that sense, our melee system will focus on making the hits their own scenes instead of having “hidden” hit boxes that activate or deactivate based on an animation. To get my weapon system, use the link below.

Download Ludonaut’s Weapon System

Why are we going to use my top-down shooter weapon system? Because it ensures the spawned scene (Bullet, or in this case, Slash) matches the Weapon’s rotation. With that, we just need to create the Slash scene and a controller to rotate the weapon and create the instances of Slashes.

Creating the Slash

To create the Slash scene, we can use a Node2D as the root node and add a HitArea2D as its child. The distance between them is the attack range. In this case, 64 pixels. You can use whatever CollisionShape2D better fits your design, I’m using a RectangleShape2D. I also used a Line2D to prototype a visual effect. It looks like a piercing effect, but you got the idea. The important part here is to call the queue_free() method after the hit window ends. In this case, I used an AnimationPlayer and called the queue_free() method after 0.1 seconds.


I also set the HitData to deal 5 damage points and, in the case of this particular Slash scene, be part of the "Player" team, so it will deal damage to non-player characters.

With that, we can create our weapon controller.

Controlling the Weapon

The whole idea is quite simple; we just need to rotate the weapon according to the directional button and spawn a Slash scene once the player presses the attack button. The way we are going to handle vertical-axis attacks is similar to Hollow Knight’s: players only perform a vertical attack, be it upwards or downwards, if the respective key is pressed at the time they pressed the attack button. Otherwise, it is going to trigger a horizontal attack based on the previous triggered horizontal direction.

The KeyboardWeaponController node will request to inject the Weapon2D instance so it can handle it accordingly. For that, we use an exporter variable. The code should look like this:


With that, all we have to do is put them together. For that, we can create a test scene and set up the Weapon → WeaponData accordingly, defining its cooldown (which is the inverse of fire rate, e.g., for a cooldown of 0.3 seconds, set the fire rate to 3.0) and the attack this weapon will spawn, in our case, the MeleeSlash scene. We can ignore the cost, since we don’t have any ammo in melee attacks.


Now we are going to test the scene and see if it works.

Testing the Scene

Here, we just have to add the KeyboardWeaponController and point to the weapon. I will use an arrow so we can visualize the attack angle better.


It’s working exactly as expected. I would just increase the hit rate so we could perform attacks faster. But to be honest, with this model, we can have a range of different melee weapons, each with its own settings, using the WeaponData.

To make it even more flexible and match the whole idea of mapping one combat action to a button, we can export a variable on the KeyboardWeaponController to support multiple weapons working independently. For instance, one for melee attacks and one for spell casting.


That’s it, this is one of the improvements I want to bring to the Platformer Essentials Cookbook once we fund the Hollow Bot Update. Click below to buy the Hollow Bot Update books and courses bundle and help fund the update:


Get the Hollow Bot Learning Bundle

That said, thank you for your support. Keep developing and until the next time!

~Henrique Campos

Get Platformer Essentials Cookbook

Buy Now
On Sale!
25% Off
$9.99 $7.49 USD or more

Comments

Log in with itch.io to leave a comment.

Yes, please =)

"I’m thinking about writing a book about 10 Enemies Archetypes and how to implement them in your game, let me know in the comments if you’re interested."