I’ve seen multiple ways of making melee combat system but which is the most ideal way of making them? I’ve heard about making a hitbox with .Touched or :GetPartsInPart() or using raycasts. What are some of the pros and cons of each?
It’s always a matter of balancing safety, responsivity, and performance.
There is no best option, so what you want to use depends on what you wish to prioritize.
Personally I discourage .Touched, as it relies on instances being created for every hitbox, and exposes some risk of exploiters triggering or not triggering hitboxes when they are or aren’t supposed to.
GetPartsInPart is a very valid choice, although it does have the same con as .Touched, being that you have to create a part to act as the hitbox.
Raycasts are also a very safe choice, but with the lack of volume of rays, you will need to use more than 1 ray per hitbox, resulting in yet another balance-game betweem performance and accuracy.
You could consider using Shapecasts to solve raycasts’ issues with volume, but they are less performant than raycasts. A single shapecast can also only hit a single part (The same applies to raycasts, but if you use multiple raycasts per hit it becomes irrelevant), meaning that if you need to hit in an AOE, you will need multiple shapecasts, which impacts performance.
I personally like to use GetPartBoundsInBox, as it is quite performant and safe. It does lose a little bit of accuracy however, as it uses parts’ bounding boxes instead of their actual volume. Although this has little effect on smaller parts like player limbs.
There’s also the option of using Region3s, which are quite performant and secure. Unlike GetPartBoundsInBox, these do use parts’ actual position and orientation, rather than bounding boxes. However Region3s cannot be rotated, meaning hitboxes would have to be axis-aligned.
I have previously also used EgoMoose’s Rotated Region3 Module, which solves the issues that Region3s have, but loses a bit of performance in comparison.
There are certainly more options when it comes to handling hitboxes, but these are the ones I could think of off the top of my head, and I would personally choose one among these.
I hope this helps!
Hey Stef, thanks for this detailed answer! I will definitely try the methods you said.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.