Seeking advice on efficient hit detection for a melee combat game

Hello fellow developers,

I’m currently working on a melee combat game in Roblox and I would like to seek your advice regarding efficient hit detection methods. I want to ensure accurate and performant hit detection for melee attacks in my game.

After researching various options, I have come across three methods: raycasting [
Raycast Hitbox 4.01 Module], a magnitude and dot-product check, and the “GetPartBoundsInBox” method. However, I’m unsure which one would be the most suitable and efficient for my game.

Here’s a brief overview of the three options:

  1. Raycast Hitbox 4.01 is widely used by developers, and I’m contemplating its use for punch detection. However, I’m uncertain whether it’s suitable for blocky characters with shorter arms, as animations play a crucial role in determining successful hits. Has anyone here had experience with this module and punch detection?
  2. Magnitude Check: With this method, I calculate the vector between the attacker and enemy player’s hitbox position. Then, I use the magnitude (length) of the vector to determine if the hit is valid. I can check the enemy is infront of me with dot-product. The magnitude check offers simplicity and efficiency, but it may be slightly less accurate compared to raycasting. Oh and I should iterate over npc’s at every punch.
  3. “GetPartBoundsInBox” Method: This method involves utilizing the “GetPartBoundsInBox” function in Roblox, which returns the parts within a specified bounding box in the 3D space. It can be useful for hit detection by defining a box-shaped region and checking for parts intersecting or contained within it. This method allows for flexibility in designing combat mechanics, but it may have performance considerations when dealing with a large number of parts or complex hitbox structures.

Given the context of a melee combat game, I wanted to know if any experienced developers have insights or recommendations regarding these hit detection methods. Specifically, I’m interested in the following:

  1. Which method would be the most suitable for accurate and performant hit detection in a melee combat game?
  2. Are there any performance considerations I should be aware of when using any of these methods, especially in scenarios with a large number of players or complex hitbox structures?
  3. Are there any optimization techniques or best practices that could enhance the performance of hit detection for any of these methods?

Any advice, personal experiences, or alternative suggestions would be highly appreciated. Thank you in advance for your valuable insights!

2 Likes

Raycast Hitbox personally works best for me. For punches, I add damage points across the whole arm, not just the hand.

And if you’re worried about shorter arms, you could try forcing a certain package onto every player (e.g. every player could be blocky). This way it’s fair for everybody.

Performance-wise, I’m conflicted. If you do hit detection on the client, there’s much less potential for performance issues. But that leaves a much bigger possibility for exploitation. Of course, this issue isn’t just impacting Raycast Hitbox though.

And for optimization, I would follow these 3 tips:

  1. Use the task library
  2. Remember to disconnect any unused connections
  3. When creating instances, change its Parent property LAST

And even better, if you’re up to it, you could comb through Raycast Hitbox’s code and optimize it the best you can. I believe it’s been a good couple of months since it’s been updated, so there has to be some vulnerabilities in there.

Hope this helps,
Fizzitix

1 Like

Thank you for your detailed response and sharing your opinions. I appreciate your insights and suggestions on making the punch detection more effective.

Your suggestion of forcing a certain package onto every player, such as making every player blocky, is a fair consideration to address the issue of shorter arms. It ensures a level playing field for all players and maintains consistency in combat mechanics.

Regarding performance, I understand the dilemma of balancing client-side hit detection for better performance versus the potential for exploitation. It’s a trade-off that requires careful consideration, I will make sanity checks on the server tho.

Once again, thank you for taking the time to provide such a detailed response!

1 Like