I’ve tried quite a few things, trying to spawn them on other heights etc, but there can be more objects spawning at the same time but I dont want them to spawn inside eachother because they arrange once they can raycast on eachother, which is impossible when they spawn inside eachother and this gets my objects stuck, what would be a good way?
Objects all spawn on the same x and z axis, how can I make sure they dont spawn in the same height? even when instantiated at the same time? spawning them goes from a global script.
void InstantiateNewObject(GameObject prefab, int minimumY, int maximumY)
{
Vector3 positionToInstantiate;
Collider[] hitColliders;
do
{
positionToInstantiate = Random.Range(minimumY, maximumY);
hitColliders = Physics.OverlapSphere(positionToInstantiate, objectHeight);
} while (hitColliders.Length > 0);
Instantiate(prefab, positionToInstantiate, Quaternion.identity);
}
Take into account that maximumY won’t ever be assigned as it is exclusive. Just use InstantiateNewObject whenever you want to instantiate a new object.