Download

Get sword hit effect at impact location

I am trying spawn a hit effect at the location where a capsule witch is attached to my sword hits the enemy’s capsule. I enabled generate hit events on both sides and the collision is set blocking. But it is not working at all. I wont even get a hit event without location. The same thing with an on begin overlap event is working. But as far as I know you can’t get the hit location from the on begin overlap event.

I google for almost two hour now but I only find examples for projectiles and not swords. I hope anyone can help me :slight_smile:

Here my bluprint
78721-unbenannt.png

Well… My suggestion would depend if your character’s sword strike is always in the same location (animation). So lets say you have two animations for swinging a sword… A single swing and a special attack that maybe does a double swing (an attack form right-left and attacks on the swing back left-right). If the animation always makes contact under a crosshair or reticle then I would use a line trace system that returns the hit location.

I would also suggest maybe not using a collision sphere, as if you do a line trace on the actual character’s mesh you can return the bone name that you hit and do different levels of damage according to that bone. Head bone would take more damage than spine bone as an example.

Hope this helped in some way!

You could do the line trace from a socket on the sword to have a more flexible hit system as well (so you don’t need the anim to line up with the crosshair at all times). e.g. trace from the hilt to the end of the sword. Then you would need to have a ‘hilt’ socket of the same name for every sword variation, as well as a variable that informs the length of the sword for the trace, or perhaps the trace could be to a second socket on the sword. I don’t believe there is a way to get accurate hit location data from collision shape overlaps, as can be done with traces.

What most people are confused is what actually ComponentHit does.

Event on Component Hit triggers, when Mesh A and Mesh B is BLOCKING EACH OTHER as they touch. In 99% of the games you would want the swing to continue, so you wouldn’t want them blocking each other. But then you lose the chance of using this event, and overlap does not give the position of the overlap.

Anyhow, what you need is what Futzy says. Line trace.

It works thank you guys :slight_smile: One more problem, tho. Since my sword slash is pretty fast and it is only making one trace per frame I some times dont get the location I want.

I found it hard to explain so here a quick bad paint drawing to understand my problem :smiley:

7528688de253389bd7745fcef27ed69fe8db8642.jpeg

I had the same issue.

The solution, unfortunately, is to do SSBM-type collision.

You define the sword “hitbox” as a series of spheres. Every frame of the swing you shape-sweep from the last position of each sphere to the new position (effectively generating a string of sideways capsules). This still produces weirdness if the framerate is too low, though, since you’re only defining the hitboxes at each frame.

Or, you just ignore it entirely. Most games with melee combat do a much less robust overlap detect and then just have the attack itself notify the enemy of what kind of reaction animation to play.

Thanks this sounds interesting :slight_smile: sadly it sounds a little too complicated for me :confused:

I used kind of an silly solution for now but it is working for me. I just increase the fps to 100 and its precise enough for what I need. Thanks for all the help guys :slight_smile:

be careful doing anything so closely tied to FPS. I did that for certain visual effects (hey, they look good enough at 75, so screw it) but I promise, someone out there is gonna struggle to get 30FPS playing your game on their machine (this IS UE4 after all) and the game will be ruined for them.

The more you can decouple anything gameplay related from framerate, the better. Ideally, if the player can stomach looking at your game at 14FPS, they should be able to play it on that setting. That way, even if optimized, you can guarantee that your game won’t break spectacularly when a background process starting up causes a framerate hitch at the exact moment that some enemy spawns or whatever.

You got a good point there :confused: I will try to find a better solution for the future :slight_smile:

Coming after the fact, but new to the forum. I would suggest putting a box collision wrapping around your sword blade and fire the trace when you get a onoverlapbegin event from the box collision. I just played around making a quick VR sword game (procedural mesh slicing ftw!) and that’s the solution I’m using. It works 100%.