Hello everyone,
We’ve been trying to develop an accurate hit detection system for a melee-based game.
So far we’ve found some glaring issues and need some help to get us going in the right direction.
Specifics
We’re trying to get accurate hit detection using very fast animations. Most of the attack animations are about 1-2 seconds in length. This includes the windup, swing, and blend back to idle. The part we care about is the swing, which is about 2-3 frames of that animation. We’re having issues reliably detecting whether or not the weapon has collided with the object.
What we’ve tried
Method 1: Attaching a collision box/capsule to the weapon
This is the most straight-forward one, so its the one we went with first. We attached collision to the weapon, then played an animation montage for the swing. The issue was that with the fast animation speed, the collision box wouldn’t register a hit against the other player reliably (pictured below with my super awesome illustration).
Method 2: Traces along the weapon body
This is the method we’ve seen suggested that was used in Chivalry. This involves tracing points along the length of the weapon and comparing them against previous points in the animation to get a sort of swing path.
So this is what our implementation translated to:
The Problem:
This method is super frame dependent although slightly better than the first method. If your framerate dips a bit for whichever reason, the animation might skip a bit, or the game might hang for a second, which will absolutely destroy the trace’s reliability. The above example shows it works fine with a single player, and nothing else running, but this isn’t going to work reliably if the player has anything bogging down their machine even slightly.
(Ex: having the EventGraph open will kill performance. Pictured Below)
Method 3: Pre-computed collision path
This was a method we came up with for dealing with the accuracy/reliability part. It involves measuring the animation path in an external 3d package by hand, making a mesh out of it, then importing it back and attaching it as a component of the character. When the player begins the swing, the collision is “turned on” through an animNotify and the damage is dealt. (Pictured below)
The Problem
While this works extremely reliably, the amount of manual work needed per animation, per weapon, gets way outta hand, way too quickly (especially since we want combo’s). This would involve turning on/off dozens of weapon collision path meshes for each possible attack.
Conclusions
So we’ve found a way to do this reliably, but with terrible scaling, and a two ways to do it more procedurally, but would involve slowing down the animation speeds to a crawl to get any reliability out of them.
Does anyone have any suggestions for a better way to accomplish this?
tldr
Animations are too fast for accurate collision based detection/traces, making custom collision paths per weapon, per animation gets ridiculous fast.