Example #1
0
    private static Vector3 FindVacantLocation(Agent argSelf)
    {
        Vector3 location = new Vector3(0f, 0f, 0f);

        for (int j = 0; j < 30; j++)
        {
            location = argSelf.transform.position + AgentUtils.RandomLocation(5f);

            location.z = 0.0f;

            //check agents on location
            Collider2D[] objectColliders = Physics2D.OverlapCircleAll(location, 0.4f, LayerMask.GetMask("Agent"));

            //check if location is on ground
            bool PositionValid = Physics2D.CircleCast(location, 0.55f, Camera.main.transform.forward, 100f, LayerMask.GetMask("Ground"));

            if (PositionValid && objectColliders.Length == 0)
            {
                break;
            }
        }

        return(location);
    }