Topic: Building Colliders
I'm having trouble detecting the colliders attached to buildings on the map. I want to avoid them when I spawn gameobjects. Here're the relevant procedures:
public Vector3 CoordsToPosition(Vector2 coords)
{
m_map.GetCorners(out m_tlx, out m_tly, out m_brx, out m_bry);
Vector3 world_pos = m_tileset.GetWorldPositionWithElevation(coords, m_tlx, m_tly, m_brx, m_bry);
return world_pos;
}
public void SmartSpawnGameObject(GameObject prefab, Vector2 map_coords)
{
m_coords = map_coords;
m_prefab = prefab;
Vector3 world_pos = CoordsToPosition(m_coords);
Collider[] overlaps = Physics.OverlapSphere(world_pos, m_spawn_size);
foreach (Collider hit in overlaps)
{
Debug.Log(hit.gameObject.name);
}
// If there are no colliders in the area the unit will spawn...
if (overlaps.Length < 2)
Instantiate(prefab, world_pos, Quaternion.identity);
else
// Note that we've got to iterate through a spiral of potential spawnpoints
{
m_waitspawn = true;
}
}Right now all I'm getting back is the Tileset's collider. I check to see if there's more than one collider since right now I can't mask the Tileset from the OverlapSphere check.
Also, for when I get that sorted, is there a relatively easy way to put the buildings on a separate layer from the map? As it stands all buildings inherit the map's layer, and since there's no prefab for the buildings, it doesn't seem to be able to be specified ahead of time. Might be a good public property to add to the Buildings component.
Since you helped me with the code to determine when all the buildings have been created, I can go in after that and find them all and set the layer that way, but thought I'd ask in case there were a more elegant solution that didn't require changing the code in your component.
Thanks!