Designing Weapon Interactions | Tech Discussion


This week we began designing and implementing our game's core systems. Being  as our game primarily revolves around combat, I tried to spend a good deal of time and intentionality designing that system well.  One of the problems I had to solve was how to deal damage between the player and enemies in a way that would integrate well with all the other features we are aiming to have in the game. The main features I wanted to be conscious of were...

  • Weapons with differing damage amounts
  • Swaping between weapons during play
  • Differing player stats throughout the game that influenced the amount of damage they deal
  • Enemies with differing defense stats that influenced how much damage they take

Additionally I wanted to design this system so that it would be reusable for the player and the enemy so that either one of them could deal and receive damage in the same way.


This clearly needed to be something that was clean and modular.  

I immediately began concidering which entity should have responsibility of which behavior. It seemed to me that since the weapon was dealing damage, it ought to be responsible for calling that behavior whenever a damaging interaction took place. However, since the player and enemies would receive damage differently depending on their defense stats and the enemy type, it seemed to me like the player and enemy should be responsible for implementing their take damage behavior.  This seemed to me like a perfect application for an interface so created an interface IDamageable for taking damage which both the player and enemy implemented. The player and enemies could then use their current stats to implement unique damage taking behavior. 

This setup gave support for the differing stat future features, while being reusable for the player and the enemy, but what about swapping different weapons? I decided to create a unique object for the weapon containing a mesh, a damage amount variable, and a hitbox (as well as a custom collision layer to avoid unecissary computations) that simply checks if the colliding object is an IDamageable and calls its TakeDamage method if it is.

What about using the player's stats to influence the damage amount? Unfortunately that was as much as I could get working this week in the midst of developing other parts of the project for the system build. I have in mind for next week to create some way for the weapon to request how much damage its owner wants to deal on this attack, as well as being able to pass additional information to the IDamageable's about what kind of damage they are receiving. 


Author: Reilly da Silva

Get Mythicism

Leave a comment

Log in with itch.io to leave a comment.