float CheckCameraPoints(Vector3 from, Vector3 to) { float nearestDistance = -1.0f; // camera never hit if return with this value; RaycastHit hitInfo; Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlaneAtNear(to); // draw lines in the editor to make it easier to visualize Debug.DrawLine(from, to + transform.forward * -camera.nearClipPlane, Color.red); Debug.DrawLine(from, clipPlanePoints.UpperLeft, Color.blue); Debug.DrawLine(from, clipPlanePoints.UpperRight, Color.blue); Debug.DrawLine(from, clipPlanePoints.LowerLeft, Color.blue); Debug.DrawLine(from, clipPlanePoints.LowerRight, Color.blue); Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight, Color.cyan); Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight, Color.cyan); Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft, Color.cyan); Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperLeft, Color.cyan); // finding the nearest point if (Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo) && hitInfo.collider.tag != "Player") { 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, clipPlanePoints.LowerLeft, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } // check bumper if (Physics.Linecast(from, to + transform.forward * -camera.nearClipPlane, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } return(nearestDistance); }
float CheckCameraPoints(Vector3 from, Vector3 to) { var nearestDistance = -1f; RaycastHit hitInfo; Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlanAtNear(to); // Draw lines in the editer to make it easier to visualize /*Debug.DrawLine(from, to + transform.forward * -camera.nearClipPlane, Color.red); * Debug.DrawLine(from, clipPlanePoints.UpperLeft); * Debug.DrawLine(from, clipPlanePoints.LowerLeft); * Debug.DrawLine(from, clipPlanePoints.UpperRight); * Debug.DrawLine(from, clipPlanePoints.LowerRight); * * Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight); * Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight); * Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft); * Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperLeft);*/ if (Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "Enemy") { nearestDistance = hitInfo.distance; } if (Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "Enemy") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "Enemy") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "Enemy") { 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" && hitInfo.collider.tag != "Enemy") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } return(nearestDistance); }
float CheckCameraPoints(Vector3 from, Vector3 to) { var nearestDist = -1f; RaycastHit hitInfo; //Calculate those clip points Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlaneAtNear(to); #region Drawing Lines Pyramid for Camera Clipping //Draw lines in editor to make it easy to visualize Debug.DrawLine(from, (to + transform.forward * -Camera.main.nearClipPlane), Color.red); Debug.DrawLine(from, clipPlanePoints.UpperLeft); Debug.DrawLine(from, clipPlanePoints.UpperRight); Debug.DrawLine(from, clipPlanePoints.LowerLeft); Debug.DrawLine(from, clipPlanePoints.LowerRight); //Drawing Box Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight); Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft); Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperRight); #endregion if (Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo) && hitInfo.collider.tag != "Player") { nearestDist = hitInfo.distance; } if (Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDist || nearestDist == -1) { nearestDist = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDist || nearestDist == -1) { nearestDist = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDist || nearestDist == -1) { nearestDist = hitInfo.distance; } } if (Physics.Linecast(from, to + transform.forward * -Camera.main.nearClipPlane, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDist || nearestDist == -1) { nearestDist = hitInfo.distance; } } return(nearestDist); }
float CheckCameraPoints(Vector3 from, Vector3 to) { var nearestDistance = -1f; RaycastHit hitInfo; Camera cam = GetComponent <Camera>(); Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlaneAtNear(to); Debug.DrawLine(from, to + transform.forward * -cam.nearClipPlane, Color.red); Debug.DrawLine(from, clipPlanePoints.UpperLeft); Debug.DrawLine(from, clipPlanePoints.LowerLeft); Debug.DrawLine(from, clipPlanePoints.UpperRight); Debug.DrawLine(from, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight); Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft); Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperLeft); 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, clipPlanePoints.LowerRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, to + transform.forward * -cam.nearClipPlane, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } return(nearestDistance); }
// If nothing is hit, then it returns -1 float CheckCameraPoints(Vector3 from, Vector3 to) { float nearestDistance = -1f; RaycastHit hitInfo; // Calculate points for clipPlanePoints Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlaneAtNear(to); // Debugging // Draw lines in the editor to make it easier to visualize Debug.DrawLine(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, Color.red); Debug.DrawLine(from, clipPlanePoints.UpperLeft); Debug.DrawLine(from, clipPlanePoints.LowerLeft); Debug.DrawLine(from, clipPlanePoints.UpperRight); Debug.DrawLine(from, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight); Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft); Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperLeft); // Get the nearest Distance for when one of the linecast points hits something between the parent and camera if (Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo) && !IsCameraIgnoreOcclusion(hitInfo)) { nearestDistance = hitInfo.distance; } if (Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo) && !IsCameraIgnoreOcclusion(hitInfo)) { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo) && !IsCameraIgnoreOcclusion(hitInfo)) { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo) && !IsCameraIgnoreOcclusion(hitInfo)) { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, to + transform.forward * -GetComponent <Camera> ().nearClipPlane, out hitInfo) && !IsCameraIgnoreOcclusion(hitInfo)) { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } return(nearestDistance); }
/// <summary> /// Checks the camera points. /// </summary> /// <returns>The camera points.</returns> /// <param name="from">From.</param> /// <param name="to">To.</param> private float CheckCameraPoints(Vector3 from, Vector3 to) { var _nearestDistance = -1.0f; RaycastHit hitInfo; Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlaneAtNear(to); if (Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo, mask)) { _nearestDistance = hitInfo.distance; } if (Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo, mask)) { if (hitInfo.distance < _nearestDistance || _nearestDistance == -1) // Is it closer that previous nearDistance? { _nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo, mask)) { if (hitInfo.distance < _nearestDistance || _nearestDistance == -1) // Is it closer that previous nearDistance? { _nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo, mask)) { if (hitInfo.distance < _nearestDistance || _nearestDistance == -1) // Is it closer that previous nearDistance? { _nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, to + transform.forward * -myCamera.nearClipPlane, out hitInfo, mask)) { if (hitInfo.distance < _nearestDistance || _nearestDistance == -1) // Is it closer that previous nearDistance? { _nearestDistance = hitInfo.distance; } } return(_nearestDistance); }
float CheckCameraPoints(Vector3 from, Vector3 to) { var nearestDistance = -1f; //If there is no collision then its -1. //Any value other than -1 indicates collision RaycastHit hitInfo; //Take to point and calculate clip plane Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlaneAtNear(to); //Draw lines in the editor to make it easier to visualize Debug.DrawLine(from, to + transform.forward * -Camera.main.nearClipPlane, Color.red); Debug.DrawLine(from, clipPlanePoints.UpperLeft); Debug.DrawLine(from, clipPlanePoints.LowerLeft); Debug.DrawLine(from, clipPlanePoints.UpperRight); Debug.DrawLine(from, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight); Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft); Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperLeft); 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, clipPlanePoints.LowerRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, to + transform.forward * -Camera.main.nearClipPlane, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } return(nearestDistance); }
float CheckCameraPoints(Vector3 from, Vector3 to) { var nearestDistance = -1f; RaycastHit hitInfo; Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlaneAtNear(to); // Draw Lines in the editor to make it easier to visualize Debug.DrawLine(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, Color.red); Debug.DrawLine(from, clipPlanePoints.UpperLeft); Debug.DrawLine(from, clipPlanePoints.LowerLeft); Debug.DrawLine(from, clipPlanePoints.UpperRight); Debug.DrawLine(from, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight); Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft); Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperLeft); // ### ADDED && to ignore bullets sucksssss ####################################################################### if (Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.gameObject.tag != "bullet") { nearestDistance = hitInfo.distance; } if (Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.gameObject.tag != "bullet") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.gameObject.tag != "bullet") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.gameObject.tag != "bullet") { 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" && hitInfo.collider.gameObject.tag != "bullet") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } return(nearestDistance); }
float CheckCameraPoints(Vector3 from, Vector3 to) { var nearestDistance = -1f; RaycastHit hitInfo; Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlaneAtNear(to); Debug.DrawLine(from, to + transform.forward * playerCamera.nearClipPlane, Color.red); Debug.DrawLine(from, clipPlanePoints.upperLeft); Debug.DrawLine(from, clipPlanePoints.lowerLeft); Debug.DrawLine(from, clipPlanePoints.upperRight); Debug.DrawLine(from, clipPlanePoints.lowerRight); Debug.DrawLine(clipPlanePoints.upperLeft, clipPlanePoints.upperRight); Debug.DrawLine(clipPlanePoints.upperRight, clipPlanePoints.lowerRight); Debug.DrawLine(clipPlanePoints.lowerRight, clipPlanePoints.lowerLeft); Debug.DrawLine(clipPlanePoints.lowerLeft, clipPlanePoints.upperLeft); if (Physics.Linecast(from, clipPlanePoints.upperLeft, out hitInfo) && hitInfo.collider.tag != "Player") { nearestDistance = hitInfo.distance; clipPos = hitInfo.point; clipPos.y = (from + transform.forward * playerCamera.nearClipPlane).y; } if (Physics.Linecast(from, clipPlanePoints.upperRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance < 0) { nearestDistance = hitInfo.distance; clipPos = hitInfo.point; clipPos.y = (from + transform.forward * playerCamera.nearClipPlane).y; } } if (Physics.Linecast(from, clipPlanePoints.lowerLeft, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance < 0) { nearestDistance = hitInfo.distance; clipPos = hitInfo.point; clipPos.y = (from + transform.forward * playerCamera.nearClipPlane).y; } } if (Physics.Linecast(from, clipPlanePoints.lowerRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance < 0) { nearestDistance = hitInfo.distance; clipPos = hitInfo.point; clipPos.y = (from + transform.forward * playerCamera.nearClipPlane).y; } } if (Physics.Linecast(from, to + transform.forward * this.GetComponent <Camera>().nearClipPlane, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance < 0) { nearestDistance = hitInfo.distance; clipPos = hitInfo.point; clipPos.y = (from + transform.forward * playerCamera.nearClipPlane).y; } } return(nearestDistance); }
//Realiza la misma función que CheckCameraPoints, solo que utilizando el reactángulo de visión de la cámara en los dos extremos private float CheckCameraPoints2(Vector3 from, Vector3 to) { var nearestDistance = -1f; RaycastHit hitInfo; //aqui almacenaremos info sobre lo que hemos chocado Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlaneAtNear(to); Helper.ClipPlanePoints clipPlanePoints2 = Helper.ClipPlaneAtNear(from); //cogemos el rectangulo de vision //Dibujamos 4 lineas que van desde el lookAt hasta ĺos 4 puntos de la cámara Debug.DrawLine(clipPlanePoints2.upperLeft, clipPlanePoints.upperLeft, Color.red); Debug.DrawLine(clipPlanePoints2.lowerLeft, clipPlanePoints.lowerLeft, Color.red); Debug.DrawLine(clipPlanePoints2.upperRight, clipPlanePoints.upperRight, Color.red); Debug.DrawLine(clipPlanePoints2.lowerRight, clipPlanePoints.lowerRight, Color.red); //Dibujamos el rectángulo de visión de la cámara 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); //Dibujamos el rectángulo de visión 2 de la cámara Debug.DrawLine(clipPlanePoints2.upperLeft, clipPlanePoints2.upperRight, Color.red); Debug.DrawLine(clipPlanePoints2.upperRight, clipPlanePoints2.lowerRight, Color.red); Debug.DrawLine(clipPlanePoints2.lowerRight, clipPlanePoints2.lowerLeft, Color.red); Debug.DrawLine(clipPlanePoints2.lowerLeft, clipPlanePoints2.upperLeft, Color.red); //Comprobamos que hemos dado a algo que no es la layermask if (Physics.Linecast(clipPlanePoints2.upperLeft, clipPlanePoints.upperLeft, out hitInfo, layerMask)) { nearestDistance = hitInfo.distance; } //Si le hemos dado a algo mas cercano, cambiamos la distancia mas cercana if (Physics.Linecast(clipPlanePoints2.lowerLeft, clipPlanePoints.lowerLeft, out hitInfo, layerMask)) { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } //Si le hemos dado a algo mas cercano, cambiamos la distancia mas cercana if (Physics.Linecast(clipPlanePoints2.upperRight, clipPlanePoints.upperRight, out hitInfo, layerMask)) { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } //Si le hemos dado a algo mas cercano, cambiamos la distancia mas cercana if (Physics.Linecast(clipPlanePoints2.lowerRight, clipPlanePoints.lowerRight, out hitInfo, layerMask)) { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } //Si le hemos dado a algo mas cercano, cambiamos la distancia mas cercana if (Physics.Linecast(from + transform.forward * -Camera.main.nearClipPlane, to + transform.forward * -Camera.main.nearClipPlane, out hitInfo, layerMask)) { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } return(nearestDistance); }
float CheckCameraPoints(Vector3 from, Vector3 to) { float nearestDistance = -1f; int layerMask = 1 << collisionLayermask; RaycastHit hitInfo; Helper.ClipPlanePoints CPP = Helper.ClipPlaneAtNear(to); //Draw lines in the editor to make it easier to visualize this was my mechanism to debug or test blah blah blah Debug.DrawLine(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, Color.red); Debug.DrawLine(CPP.BottomLeft, CPP.BottomLeft + transform.forward * 0.1f); Debug.DrawLine(CPP.BottomRight, CPP.BottomRight + transform.forward * 0.1f); Debug.DrawLine(CPP.UpperLeft, CPP.UpperLeft + transform.forward * 0.1f); Debug.DrawLine(CPP.UpperRight, CPP.UpperRight + transform.forward * 0.1f); Debug.DrawLine(from, CPP.BottomLeft); Debug.DrawLine(from, CPP.BottomRight); Debug.DrawLine(from, CPP.UpperLeft); Debug.DrawLine(from, CPP.UpperRight); Debug.DrawLine(CPP.UpperRight, CPP.UpperLeft); Debug.DrawLine(CPP.BottomRight, CPP.BottomLeft); Debug.DrawLine(CPP.UpperRight, CPP.BottomRight); Debug.DrawLine(CPP.UpperLeft, CPP.BottomLeft); if (Physics.Linecast(from, CPP.BottomLeft, out hitInfo, layerMask)) { nearestDistance = hitInfo.distance; } if (Physics.Linecast(from, CPP.BottomRight, out hitInfo, layerMask)) { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, CPP.UpperLeft, out hitInfo, layerMask)) { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, CPP.UpperRight, out hitInfo, layerMask)) { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, out hitInfo, layerMask)) { if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } return(nearestDistance); }
//Checking here from and to the "pyramid" of N.C.P. and ProtoLookAt float CheckCameraPoints(Vector3 from, Vector3 to) { //series of comparisons, IF any of the 5 determined points is hit, what is //nearest of desired target for cam. //nearest distance can never be -1. It can be 0, but not less than that. //If this returns any other value than -1, there is a collision var nearestDistance = -1f; //if this is coming out, there has not been a collision. //Linecast is similar to raycast. Raycast also needed for check RaycastHit hitInfo; //let's calculate the clipPoints of plane. By calling helper :D HELP! HELPER! Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlaneNear(to); //Draw Lines in editor for visualization. To see the actual rays. //JUST DEBUGGING!!! Visible in editing-mode while running game. Debug.DrawLine(from, to + transform.forward * -Camera.main.nearClipPlane, Color.green); //from = protoLookAt, to is a point in space... oo.. Debug.DrawLine(from, clipPlanePoints.UpLeft); Debug.DrawLine(from, clipPlanePoints.UpRight); Debug.DrawLine(from, clipPlanePoints.LowLeft); Debug.DrawLine(from, clipPlanePoints.LowRight); //still debugging.... Debug.DrawLine(clipPlanePoints.UpLeft, clipPlanePoints.UpRight); Debug.DrawLine(clipPlanePoints.UpRight, clipPlanePoints.LowRight); Debug.DrawLine(clipPlanePoints.LowRight, clipPlanePoints.LowLeft); Debug.DrawLine(clipPlanePoints.LowLeft, clipPlanePoints.UpLeft); //DEBUG ENDS HERE //Throwing lines to check for collision. if (Physics.Linecast(from, clipPlanePoints.UpLeft, out hitInfo) && hitInfo.collider.tag != "Proto") { nearestDistance = hitInfo.distance; } if (Physics.Linecast(from, clipPlanePoints.LowLeft, out hitInfo) && hitInfo.collider.tag != "Proto") { //if this point is closer to collision than the previous point, then this becomes the nearest distance. if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.UpRight, out hitInfo) && hitInfo.collider.tag != "Proto") { //if this point is closer than the previous point, then this becomes the nearest distance. if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.LowRight, out hitInfo) && hitInfo.collider.tag != "Proto") { //if this point is closer than the previous point, then this becomes the nearest distance. if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } //This is the bumper-point behind the camera. This actually should never happen. if (Physics.Linecast(from, to + transform.forward * -Camera.main.nearClipPlane)) { // if this point is closer than the previous point, then this becomes the nearest distance. if (hitInfo.distance < nearestDistance || nearestDistance == -1) { nearestDistance = hitInfo.distance; } } return(nearestDistance); }
float CheckCameraPoints(Vector3 from, Vector3 to) { float nearestDist = -1; RaycastHit hitInfo; Helper.ClipPlanePoints clipPlanePoints = Helper.ClipPlaneAtNear(to); //Draw line in editor for debug purposes Debug.DrawLine(from, to - transform.forward * cam.nearClipPlane, Color.red); Debug.DrawLine(from, clipPlanePoints.bottomLeft); Debug.DrawLine(from, clipPlanePoints.bottomRight); Debug.DrawLine(from, clipPlanePoints.topLeft); Debug.DrawLine(from, clipPlanePoints.topRight); Debug.DrawLine(clipPlanePoints.bottomLeft, clipPlanePoints.bottomRight); Debug.DrawLine(clipPlanePoints.topLeft, clipPlanePoints.topRight); Debug.DrawLine(clipPlanePoints.topLeft, clipPlanePoints.bottomLeft); Debug.DrawLine(clipPlanePoints.topRight, clipPlanePoints.bottomRight); if (Physics.Linecast(from, clipPlanePoints.bottomLeft, out hitInfo, collisionLayers)) { if (hitInfo.distance < nearestDist) { nearestDist = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.topLeft, out hitInfo, collisionLayers)) { if (hitInfo.distance < nearestDist || nearestDist == -1) { nearestDist = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.bottomRight, out hitInfo, collisionLayers)) { if (hitInfo.distance < nearestDist || nearestDist == -1) { nearestDist = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.topRight, out hitInfo, collisionLayers)) { if (hitInfo.distance < nearestDist || nearestDist == -1) { nearestDist = hitInfo.distance; } } if (Physics.Linecast(from, to - transform.forward * cam.nearClipPlane, out hitInfo, collisionLayers)) { if (hitInfo.distance < nearestDist || nearestDist == -1) { nearestDist = hitInfo.distance; } } return(nearestDist); }