Raycast Arrays

Hello all, I am trying to do a collision detection and object avoidance script for a moving around in 3d space. I think I am going to try this with a system of 14 different Raycasts. Problem is, I am trying to figure out a way to store each Racycast within an array, that way I can easily reference each raycast though out the script. I can make the array of raycasts, but I cannot figure out how to set each element of the array to an individual ray, or is that even possible? any help would be appreciated.

RaycastHit castArray = new RaycastHit[14];

 RaycastHit[] f = Physics.RaycastAll (transform.position,transform.forward,50);
 
 for (int i = 0; i < f.Length; i++)
 {
     if (f_.transform != transform && f*.collider.tag != "Terrain")*_

{
castArray [0] = f*;*
fDetected = true;
}

}
Per the comments the following code worked for you.
However, unless their is preceding code that loops through the 14 expected RayCastAll calls your castArray will be:
castArray[0] = possible hit
castArray[1] = null
castArray[2] = null
castArray[3] = null
castArray[4] = null
castArray[5] = null
castArray[6] = null
castArray[7] = null
castArray[8] = null
castArray[9] = null
castArray[10] = null
castArray[11] = null
castArray[12] = null
castArray[13] = null
I got an email update on this thread from you (that for some reason I don’t see on this question) that said:
>Will this cast all 14 rays in the same direction? I want each of the 14 rays to be >casted out in a different direction (forward, -forward, up, -up, right, -right, etc.)
With the code I posted it wont cast in 14 directions at once.
Even if you have preceding code that casts in 14 directions then loops through each RaycastHit[], I would recommend you use SphereCastAll.
SphereCast and SphereCastAll cast a sphere from your originating point. This sphere can travel but doesn’t have to.
SphereCast can be used to detect an explosion radius to tell all objects hit by the sphere to take damage (think like a grenade).
SphereCast can also be used to draw a fat ray from the transform to detect for objects in relative position. This is helpful when you have a first person player trying to interact with an object. Using a Ray is a fine line and if the object is small you have to be very accurate and your FPS camera has to be lined up with where the raycast is being drawn from. Instead using a spherecast can make it so the user doesn’t have to be exactly on the object but rather the object they are interacting with just has to be in their window since its drawing a fat array.
Mind my crude drawing but there isn’t enough detailed information on SphereCasting.
[40086-spherecast.png|40086]

I believe if you are trying to just get all objects that is NOT the transform and is NOT tagged as “Terrain” in ALL directions you should do the following.
RaycastHit[] castArray = Physics.SphereCastAll (transform.position,50,transform.forward,0);

for (int i = 0; i < castArray.Length; i++)
{
if (castArray_.transform != transform && castArray*.collider.tag != “Terrain”)
{
fDetected = true;
}*_

}
Also, instead of using a tag. If you set your Terrain to Layer you can exclude all terrain from your SphereCast using its optional Layermask (this is integer based on the integer id of the layer).
If you set Terrain to integer 9 in EDIT → Project Settings → Tags and Layers.
Then simply use
RaycastHit[] castArray = Physics.SphereCastAll (transform.position,50,transform.forward,0,9);

if(castArray != null)
{
* fDetected = true*
}
You wont get 14 direction array but rather an array of all objects within 50 units of your transform. This could be 1 object, this could be 1000 objects.
I hope this does help you and I didn’t go off on a tangent. Good luck!