Melee Combat Collision

Hi All

I am trying to get some melee combat working; in this case I have a character (3rd person) with various attack animations. One or two of these animations seems to be too fast for the system, here is what I have done.

The character has a sword equipped (with a collider on the blade). When the character attacks an attack animation is triggered, when the animation reaches a certain point an AnimationEvent is fired (this event just sets a bool used to determine if the collision should be handled or not - used to avoid attacking an enemy when walking into one for example).

This works well, most of the time! But what I am experiencing is that once in a while the sword passes through the target without hitting, but then it hits on the return trip (by that I mean that the animation pulls the sword back to the ready stance after swinging, and this drags the blade (and hence the collider) through the target and triggers the hit).

So in short it seems that the sword passes through the enemy collider sometimes too fast (it is a fast attack). This is also something I have seen others mention that perhaps the animation is so fast that the position of the blade skips such a distance that at one frame it is “to one side of the enemy collider” and the next frame it is “on the other side of the enemy collider”?

In any case, I have tried to slow the animation and increase the enemy collider size, both seems to do the trick, however I would like to hear if there is a better solution for this “issue” and if it is indeed happening because the attack animation is too “fast paced”.

Also would I be better off dropping the collider approach and instead make an AnimationEvent at the point where the sword is supposed to “hit” and then do a RayCast in this event to check if an enemy is close enough and handle the hit here.

I hope it makes sense to someone!!!

This might sound confusing but I think I know a fix. When you hit the attack key or button make it so it enables a game object with a box collider in front of the player. Then make it so when the box collider collides with the enemy then send a message dealing the damage. I hope this worked if not try using it as a trigger instead. Hoped this helped

As you press the attack button send a raycast (just for example with a range of 2) and if it hits the enemy
(lets say it has a “Enemy” tag then deal the damage, something like that:

var hit : RaycastHit;

void Update() {
       Vector3 fwd = transform.TransformDirection(Vector3.forward);
       if (Physics.Raycast(aaaaaa, fwd, hit, 2) && hit.transform.tag == "Enemy") {
            print("There is something in front of the object!");