Raycast & melee fight

Hey guys (and girls?). I wanted to make a sword fight using Raycast (View from the 3rd person). Here’s the code:

public void sendDmg()
{
RaycastHit hit;
if (Physics.Raycast(DmgRay.position, DmgRayTo.position - DmgRay.position, out hit, 4f))
{
if (hit.transform.tag == “Enemy”)
{
Enemy = hit.collider.gameObject;
Instantiate(DeadEnemy, Enemy.transform.position, Enemy.transform.rotation);
Destroy(Enemy);
}
}
}
P.s:
DmgRay - Point at the base of the sword;
DmgRayTo - Point at the end of the sword;

Like all works, but not quite right. Ray does not always gets to the target. videos:

Can tell me how to do it better? )

(Sorry for my bad English. Translated by Google =))

I have recently implemented a melee system in my game. Originally I used this raycast solution but found that it wasn’t completely satisfactory.

From there I switched to a box collider on the weapon and using OnTriggerEnter to detect the collisions.

This solution works good.

However, I recently found a third method which I’m currently using.

Which, is to use Physics.OverlapSphere to detect the collisions.