Beispiel #1
0
    //additional checks if the point is valid. Return true if it's valid
    public bool NarrowDownValidSpawnPoints(Vector3 point)
    {
        //check if the point is in range of the agent at all
        GameObject agent = GameObject.Find("FPSController");
        PhysicsRemoteFPSAgentController agentController = agent.GetComponent <PhysicsRemoteFPSAgentController>();

        //get agent's camera point, get point to check, find the distance from agent camera point to point to check

        float maxvisdist = agentController.WhatIsAgentsMaxVisibleDistance();

        //set the distance so that it is within the radius maxvisdist from the agent
        Vector3 tmpForCamera = agent.GetComponent <PhysicsRemoteFPSAgentController>().m_Camera.transform.position;

        tmpForCamera.y = point.y;

        //automatically rule out a point if it's beyond our max distance of visibility
        if (Vector3.Distance(point, tmpForCamera) >= maxvisdist)
        {
            return(false);
        }

        //ok cool, it's within distance to the agent, now let's check
        //if the point is within the viewport of the agent as well

        Camera agentCam = agent.GetComponent <PhysicsRemoteFPSAgentController>().m_Camera;

        //no offset if the object is below the camera position - a slight offset to account for objects equal in y distance to the camera
        if (point.y < agentCam.transform.position.y - 0.05f)
        {
            //do this check if the point's y value is below the camera's y value
            //this check will be a raycast vision check from the camera to the point exactly
            if (agentController.CheckIfPointIsInViewport(point))
            {
                return(true);
            }
        }

        else
        {
            //do this check if the point's y value is above the agent camera. This means we are
            //trying to place an object on a shelf or something high up that we can't quite reach
            //in this case, modify the point that is checked for visibility by adding a little bit to the y

            //might want to adjust this offset amount, or even move this check to ensure object visibility after the
            //checkspawnarea corners are generated?
            if (agentController.CheckIfPointIsInViewport(point + new Vector3(0, 0.05f, 0)))
            {
                return(true);
            }
        }

        return(false);
    }