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.