How to handle collision for fast melee animation at lower FPS?

Hello everyone,

I’m struggling to resolve this issue. In my game, melee combat makes up a large chunk of the gameplay, so it must be as frame independent as possible. Unfortunately, when I test out the collision at lower FPS (20 fps), the melee swings are missed completely. Currently the collision consists of simply a collision box with CCD enabled attached to a mesh, and that mesh is attached to the player’s hand. At higher FPS it works perfectly, but once you dip below 30 it starts to miss very clear hits.

Here’s what I have attempted:

  • Enable physics substepping: I enabled this setting and played with the values and saw absolutely no difference in the accuracy of the collision. At 20FPS the swings still missed.
  • CCD: Also no difference.
  • My own custom collision: I coded my own simple collision system in C++ similar to the way Chivalry handled theirs; line traces drawn between the previous frame and the current frame along two sockets. Unfortunately at lower FPS the shape still gets distorted enough that a lot of weapon range is lost.

Are my animations just too fast that I can’t use them reliably? Is there anything I can do to achieve reliable collision at lower FPS? 20FPS I’d consider a realistic dip, but even at 25FPS collision still misses.

Wasn’t Street Fighter V made in UE4? How did they handle their collision, it can’t be framerate dependent can it?

Thank you for any help.

Are you testing that the box collides with a mesh or some other collider (on the receiving end of the melee attack)?

Currently I’m just testing against Pawn, so in the case right now that would be the CapsuleComponent that is the default root of Characters. I might want to move it to mesh in the future though, does that have any effect on the accuracy on the collision?

Thanks for the reply!

That should be fine. And is the capsule also set to CCD?

It wasn’t, but I turned it on just now and the issue still persists. I thought about going with something along the lines of a pre-calculated sweep, such as spawning a large collider during the apex of the swing, but then if I hit multiple targets they will all get sent back at the same time and it won’t feel organic.

CCD should be doing that already. That’s how it works. Are you using block or overlap? Pretty sure CCD only works with block. Next time I reply I’ll move this to a (potential) answer.

I was using overlap… I switched it to block but now I can barely walk since the sword itself is pushing the character haha. I managed to get close enough to the enemy to test it out and it’s more or less the same, but hard to tell since it actually pushes now… How do you recommend I test this?

Thank you so much for your help!

So what you want to do is use the block as well as the ‘hit’ events (“On Overlap” won’t work anymore). Then you need to make sure the colliders don’t collide with their owning actors. Most of that functionality involves the label “ignore”, like “Ignore Actors” or “Ignore Self”.

You may also need to set up collision channels so the weapons only hit what they need. But since your combatants are the same class (I assume) that won’t be enough. If they happen to be different kinds of actors then it’s pretty straight forward to set up two collsion channels so the weapons of one actor only hit the other type of actor (and vice versa) – as well as any obstacles, which should be blocked as well.

I learned about this type of functionality by watching a tutorial from Epic. I’m pretty sure it covers what you need… It can be found here BP 3rd Person Game: Introduction | 01 | v4.8 Tutorial Series | Unreal Engine - YouTube.

Let me know if that isn’t sufficient.

That sounds like the physics. If you want the hits to include physics reactions then it’s a bit more complicated. Otherwise, you can turn off “Simulate Physics” but keep the collision set to “Enable Collision (Query and Physics)”. Then you’ll get the hit events without the impacts causing movement. You can implement your own physics reactions using the mesh component (basically on hit you call “Add Impulse” and give it a component, location, – and, if you want, the bone – that got hit). But note that physics with skeletal meshes can get a bit unruly. Having hit reaction animations may not look as good as a well-implemented physics system, but it’s way easier programmatically.

Thanks for the answer! I’m almost there, but I can’t figure out how to get past one thing. My hits are not being detected unless at least one of the two actors has “simulate physics” enabled. If I enable simulate physics, then if there is a collision the one simulating physics goes flying. Is there a way to get hit events without simulate physics on?

Oh, I misremembered. You want to set “Collision Enabled” in “Collision Presets” to “Query Only” (No Physics Collision)". Then you should get the hits.

I just tried it on both, but no hit events fire now. If I set collision enabled on both of them and enable simulate physics on one of them, then it works, but I can’t use that since then gravity is applied and the issue described above. Have you managed to get it working like this?

I looked at a working project. My bullets and mesh are set to Query only and the bullet hits the mesh, firing the hit event. It might be that the collision channels are not set to block the right object types. Though disabling physics shouldn’t change that.

I’m glad to hear it’s working for you, that means I’m just doing something wrong. Would you mind helping me out?
Here are the exact same collision settings I’m using for both the sword, and the mesh I’m trying to hit:

Like you said, it’s probably not something directly in the collision settings since as soon as I set either of them to simulate physics (and both to collision enabled instead of query) it works.

If you’re using the capsule then set the Pawn to Block. And make sure the capsule’s object type is pawn (the default, or set it to whatever object type you changed it to). You also want the capsule to have Block set for the Weapon object type.

Ah no, right now I’m literally just placing a collision box with those settings, which are the same settings that the sword has. Since they’re both of type weapon then they should call “hit” when they overlap no?

The weapons will collide based on those settings. In addition, you need the weapons to hit the capsules (you said you were using capsule at the moment). The capsules (by default) are set to Pawn as the object type, so you also need to tell UE4 to catch the collisions between the Weapon and the Pawn object types. You do that by setting the Pawn to block Weapon and the Weapon to block Pawn. And make sure “Simulate generates hit events” is set on both components.

Yes, I was testing using the capsule, but to speed up testing I just placed a collision box with the settings above and tried hitting it with the sword. It should still work right? The settings above are the ones that both the sword AND the box I’m trying to hit have. Since they are both the same type and both are blocking each other, it should still work, but it doesn’t.

Thanks again!

I’ll mark yours as the answer and I’ll make a new thread for this since it’s unrelated to my specific issue. Thanks for the help.

I thought the sword was being represented by the box. You have a collision object on that too, right? Mesh collisions are very costly. Either way, the object type of one actor needs to be marked as blocked in the other and vice versa. GL!

Sorry, please re-mark the answer. I hate that you can’t reply without undoing that…