Hello!
I’ve been trying to make a satisfying, and easy to setup melee combat system.
I don’t want accurate collision detection (aka attaching hit boxes to swords), I want to make it reliable, also I want to make many different weapons, each responsible for it’s own collision instead of putting many hitboxes in my character blueprint.
For example, there is a sword which have light slash, heavy slash, a dash, and a jump attack.
Light and heavy slash should be one time collision ( an event in the montage ) when it check if there is anyone in front of my character, max x distance, and lets say 120 degrees angle, max z height distance. I can do calculations for it (distance check, heigh distance check, and angle check ), but it’s hard to setup unless I see it visually.
My current workflow is:
i have a weapon BP
I put the character model in my weapon BP, marked as editor only, hidden in game, no collision (this is just for reference)
Put box components in the weapon BP, turned off collision, positioned to the right position according to my character I put there
On the right anim event, I turn on the corresponding box component, find anyone inside of it, then turn it off, then deal damage to them.
It’s nice, because I can visually setup the collision, easy to use, easy to modify. However, I can only use, box, sphere and capsule collision with it, which is pretty lame.
I could go and use static meshes as colliders (convex collision), but that’s hard to modify, or could go and write down the values, and that’s hard to setup.
just a quick thought,
what if you use the primitive collision at the max size (angle+ range) and then for each hit actor check if its withing the bounds of your angle with simple direction calculation?
If you don’t want to use PhysX collisions then you’ll have to use distance measuring, dot-product and cross product math to detect hits…
Combined with named sockets attached to strategic bones of your character’s skeleton, it’s doable.
What I’ve got that works really well. It’s similar to your setup except that it uses a single hit-box mesh on the character and scales it to fit the attack, making multiple attacks very easy to use. (We also use a full cylindrical and turn that on instead for full AoE attacks)
A half-cyllinder hitbox attached to the front of the character. It’s shaped to cover the slash area in front of him.
Then I scale it the size I want and record the relative location/scale for each attack.
There is then an overlap event attached to the hitbox that checks for enemies.
When the character does the attacks, it sets the hitbox to the sizes I recorded above based on the attack, and enables it’s collision for 0.2 seconds, effectively “hitting” all enemies in the attack range. It works extremely well and gives that nice gamey feel of everyone in the hit-area being hit at once. Plus you can easily see and adjust attack sizes using the hitbox in editor.
We have a “debug mode” that can be toggled on, which in addition to other things, also makes the hitbox visible when it activates. This way it’s very easy to see the actual hitboxes in game. (can’t do that with capsules/collision shapes)