Ranged hitboxes I think are pretty straightforward to do, so I don’t think I need to go over that (besides, I think these other lovely people can give more insight on ranged combat if you need that).
For melee hit boxes, I use raycasting. A few years back, I’ve been intrigued by the design of MORDHAU and Chivalry since I wanted accurate hitboxing while making it simple to do across a variety of different weapon shapes and sizes. Here’s a timestamp of how MORDHAU did their hitbox for their swords which may prove to be helpful.
Warning: Does include realistic depiction of blood so please be aware before opening
A few examples that I’ve done that uses this system. It basically fires a ray from an attachment placed on the weapon every frame. Do note that the red lines are visualizations purposes only, they do not last that long.
I also made it so you can adjust the placements of where the raycasting starts via attachments so I can fit it on different weapon shapes easily without hardcoding it. Here is the same system but the attachments are spread out a little to compensate for larger hitboxes.
In the past I’ve used GetTouchingParts and Region3 for these stuff with angle checks, but that proved far too performance heavy for the type of game I was making. I was surprised, the performance was actually improved after switching over to this system since while, yes there are a lot of rays being made in a short span of time, they were also really small so the performance drop was negligible.
Edit: Another big plus on using raycasting for melee weapons is that, you can make really fast and fluid melee combat while always retaining accurate hitboxes. Using touched or similar methods I’ve tested, sometimes when the move goes too fast, the physic engine doesn’t register it.