private float CheckCameraPoints(Vector3 from, Vector3 to)
    {
        var nearestDistance = -1f;

        RaycastHit hitInfo;

        var clipPlanePoints = ThirdPerson_Helper.ClipPlaneAtNear(to);

        /* Don't include Debug's in out of the box script
         *
         * // Draw the raycasts going through the near clip plane vertexes.
         * Debug.DrawLine (from, to + myTransform.forward * -myCamera.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.CompareTag(PLAYER_TAG))
        {
            nearestDistance = hitInfo.distance;
        }
        if (Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo) && !hitInfo.collider.CompareTag(PLAYER_TAG))
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1)
            {
                nearestDistance = hitInfo.distance;
            }
        }
        if (Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo) && !hitInfo.collider.CompareTag(PLAYER_TAG))
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1)
            {
                nearestDistance = hitInfo.distance;
            }
        }
        if (Physics.Linecast(from, to + myTransform.forward * -myCamera.nearClipPlane, out hitInfo) && !hitInfo.collider.CompareTag(PLAYER_TAG))
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1)
            {
                nearestDistance = hitInfo.distance;
            }
        }

        return(nearestDistance);
    }
Example #2
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);
    }
Example #3
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);
    }