- Home /
Creating multiple rays/objects based off of a variable?
Hola! I'm working on a "modular" weapons system for my FPS that will allow me to easily create any standard cliche' weapon that I need- But I'm a bit stumped on this one. Please see my code snippet below. Basically I have a variable called travelspread that I want to use in order to control how many rays and objects are instantiated- If travelspread is set to 1 then you would get a single ray and a single prefab travelling towards the target (Which is what I have), but what I need help implementing is when travelspread is any higher than 1, instead of a single ray and prefab travelling towards the target, you have x amount of prefabs and rays which spread out at an angle. For instance, it would spread out in a V formation when shot with travelspread set to 2, or a \|/ formation when it is set to 3. I appreciate the help in advance (You can probably tell that I'm new here)
Instantiate (bullet, transform.position, transform.rotation);
RaycastHit hit;
Ray ray = new Ray (transform.position, transform.forward);
if (Physics.Raycast (ray, out hit, Gun.travelrange)) {
Instantiate (bullethole, hit.point, Quaternion.FromToRotation (Vector3.up, hit.normal));
}