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 =))