Shotgun script (need help)

Hi guys I’ve finished shotgun for my game except the spread. My gun shoots multiple rays in some sort of spread. Altho there are 8 bulletholes they’re all stacked on top of each other and i cant increase the spread. Can anyone help me ? Thanks

Can anyone help me ? Thanks.

var spread : float  = 	11.1; // it seems it doesnt matter what number i type
var hit : RaycastHit;
var ray = transform.TransformDirection (Vector3.forward);

for (var i = 0; i < 8; i++)

{
  ray.x += Random.Range(-spread, spread);
  ray.y += Random.Range(-spread, spread);
  Debug.DrawRay(transform.position, ray * 10, Color.red);
}
	
cooldown = time + 1;
audio.PlayOneShot(shotgun_shot,5);
	
	
  if (Physics.Raycast (transform.position,ray,hit, 10))
{
  for (var j = 0; j < 8; j++)
   {
   Instantiate(bulletHole[Random.Range(0,2)], hit.point,Quaternion.FromToRotation(Vector3.up, hit.normal));
   }
}

You need to raycast inside the for loop AFTER you randomize the spread. There is no memory in which all the ray positions are so you will always have a shot in one location. Also, take out the for loop inside the “if” statement as you will not need it after you put the raycast inside the first for loop.

Great, thank you for your help :stuck_out_tongue:

For anyone wondering :

var hit : RaycastHit;
var ray = transform.TransformDirection (Vector3.forward);



for (var i = 0; i < 8; i++)

{
	ray.x += Random.Range(-rozptyl, rozptyl);
	ray.y += Random.Range(-rozptyl, rozptyl);
	Debug.DrawRay(transform.position, ray * 10, Color.red);

if (Physics.Raycast (transform.position,ray,hit, 10))
	{
	Instantiate(bulletHole[Random.Range(0,2)], hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
    hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
	print ("HIT !");
	}
}