Ejemplo n.º 1
0
    private float CheckCameraPoints(Vector3 from, Vector3 to)
    {
        float nearestDistance = -1f;

        RaycastHit hitInfo;

        ThirdPerson_Helper.ClipPlanePoints clipPlanePoints =
            ThirdPerson_Helper.ClipPlaneAtNear(to);


        // Draw the raycasts going through the near clip plane vertexes.
        Debug.DrawLine(from, to + transform.forward * -GetComponent <Camera> ().nearClipPlane, Color.red);
        Debug.DrawLine(from, clipPlanePoints.upperLeft, Color.red);
        Debug.DrawLine(from, clipPlanePoints.upperRight, Color.red);
        Debug.DrawLine(from, clipPlanePoints.lowerLeft, Color.red);
        Debug.DrawLine(from, clipPlanePoints.lowerRight, Color.red);
        Debug.DrawLine(clipPlanePoints.upperLeft, clipPlanePoints.upperRight, Color.red);
        Debug.DrawLine(clipPlanePoints.upperRight, clipPlanePoints.lowerRight, Color.red);
        Debug.DrawLine(clipPlanePoints.lowerRight, clipPlanePoints.lowerLeft, Color.red);
        Debug.DrawLine(clipPlanePoints.lowerLeft, clipPlanePoints.upperLeft, Color.red);


        if (Physics.Linecast(from, clipPlanePoints.upperLeft, out hitInfo) && hitInfo.collider.tag != "Player")
        {
            nearestDistance = hitInfo.distance;
        }
        if (Physics.Linecast(from, clipPlanePoints.lowerLeft, out hitInfo) && hitInfo.collider.tag != "Player")
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1)
            {
                nearestDistance = hitInfo.distance;
            }
        }
        if (Physics.Linecast(from, clipPlanePoints.upperRight, out hitInfo) && hitInfo.collider.tag != "Player")
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1)
            {
                nearestDistance = hitInfo.distance;
            }
        }
        if (Physics.Linecast(from, to + transform.forward * -GetComponent <Camera> ().nearClipPlane, out hitInfo) && hitInfo.collider.tag != "Player")
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1)
            {
                nearestDistance = hitInfo.distance;
            }
        }

        return(nearestDistance);
    }
Ejemplo n.º 2
0
    private bool CheckBehindCam(Vector3 to)      // Checks the area behind the camera to make sure the camera can back up to its desired spot
    {
        RaycastHit hitInfo;

        Vector3 pos = CalculatePosition(mouseY, mouseX, preOccludedDistance);

        ThirdPerson_Helper.ClipPlanePoints clipPlanePoints =
            ThirdPerson_Helper.ClipPlaneAtNear(to);

        /* Debug.DrawLine(this.transform.position, pos, Color.blue);
         * Debug.DrawLine(clipPlanePoints.upperLeft, pos, Color.blue);
         * Debug.DrawLine(clipPlanePoints.upperRight, pos, Color.blue);
         * Debug.DrawLine(clipPlanePoints.lowerLeft, pos, Color.blue);
         * Debug.DrawLine(clipPlanePoints.lowerRight, pos, Color.blue);
         */
        if (Physics.Linecast(clipPlanePoints.upperLeft, pos, out hitInfo))
        {
            return(false);
        }
        if (Physics.Linecast(clipPlanePoints.upperLeft, pos, out hitInfo))
        {
            return(false);
        }
        if (Physics.Linecast(clipPlanePoints.upperRight, pos, out hitInfo))
        {
            return(false);
        }
        if (Physics.Linecast(clipPlanePoints.lowerLeft, pos, out hitInfo))
        {
            return(false);
        }
        if (Physics.Linecast(clipPlanePoints.lowerRight, pos, out hitInfo))
        {
            return(false);
        }
        return(true);
    }