in my game I gave 2 spheres that change direction I want there to be a collider to prevent anything from passing between them. any help would be appreciated?
Given two GameObjects with sphere colliders attached, we can get the midpoint between them pretty easily:
var midpoint = (objOnePos + objTwoPos ) / 2f;
Now we need to find the size of a box collider to put between them. Thats just the distance between them:
var dist = (objOnePos + objTwoPos).magnitude;
At this point we have all the data we need. Now we can create the object to hold the boxCollider. You would obviously reuse a previously existing object/component after doing this the first time, but for this example I’ll make new ones:
var boxObj = new GameObject();
var box = boxObj.AddComponent<BoxCollider>();
boxObj.transform.position = midPoint;
boxObj.transform.LookAt(objTwoTransform);
//We subtract the sum of the radii so there is no collision between this box and the spheres
box.size = new Vector3(1f, 1f, dist - (objOneSphereRadius + objTwoSphereRadius));