I’m creating a spawn manager that creates a random environment.
Now before I place a prefab on a certain place I want to check if there is already a prefab at that location?
My thought was using Physics.CheckSphere() method. But that doesn’t seem to work.
Certain prefabs are still on top of eachother.
private void SpawnTrees()
{
Vector3 spawnPos;
for (int index = 0; index < numberOfTrees; index++)
{
spawnPos = RandomPosition(xSpawn, zSpawn);
while (!Physics.CheckSphere(spawnPos, radius))
{
spawnPos = RandomPosition(xSpawn, zSpawn);
}
Instantiate(tree, spawnPos, tree.gameObject.transform.rotation);
trees++;
}
}
for radius I even even use a big number like 5.0f
All my prefabs have a collider box
What am I doing wrong or maybe there is another way?