I have a Raycast that goes from a Unit towards an enemy with a cone effect. This is to simulate machine gun fire. But for some reason when using the following code my Rays will only hit the enemy and not around it. I have a feeling it’s something to do with the out shootHit in the Physics.Raycast if statement.
I just can’t find the cause of this issue. Any help would be greatly appreciated.
Code below:
shootDirection = rotateTransform.forward + (rotateTransform.right * Random.Range(-shootAccuracy, shootAccuracy));
RaycastHit shootHit;
if (Physics.Raycast(transform.position, shootDirection, out shootHit, shootRange))
{
Debug.DrawRay(transform.position, shootDirection * shootRange);
if (shootHit.transform.tag == "Enemy")
{
Debug.Log(D.Log(this, shootHit.transform.name + " HIT with " + activeAbility + " - Health is "));
}
}
That makes perfect sense. I was expecting the Rays to be cast around an Enemy even though there was nothing for it to collide with, little bit of confusion from me there. Thanks dude.
– samtperrin