Ejemplo n.º 1
0
    //Listens for camera control input from the player.
    void GetInput()
    {
        var deadZone = 0.01f;

        /*Must hold mouse button down to rotate camera around
         * if(Input.GetMouseButtonDown (1))
         *      ToggleCursor(false, true);
         * if(Input.GetMouseButtonUp (1))
         *      ToggleCursor(true, false);
         * if(Input.GetMouseButton (1)){
         *      if((Input.GetAxis("Mouse X") > deadZone) || (Input.GetAxis ("Mouse X") < -deadZone))
         *              mouseX += Input.GetAxis ("Mouse X") * x_camSpeed;
         *      if((Input.GetAxis("Mouse Y") > deadZone) || (Input.GetAxis ("Mouse Y") < -deadZone))
         *              mouseY -= Input.GetAxis ("Mouse Y") * y_camSpeed;
         *      //Clamp Y-Mouse movement so cam doesn't go over players head
         *      mouseY = SYS_Help.ClampAngle(mouseY, y_minLimit, y_maxLimit);
         * }
         */

        //No mouse-holding required for cam steering
        if ((Input.GetAxis("Mouse X") > deadZone) || (Input.GetAxis("Mouse X") < -deadZone))
        {
            mouseX += Input.GetAxis("Mouse X") * x_camSpeed;
        }
        if ((Input.GetAxis("Mouse Y") > deadZone) || (Input.GetAxis("Mouse Y") < -deadZone))
        {
            mouseY -= Input.GetAxis("Mouse Y") * y_camSpeed;
        }
        //Clamp Y-Mouse movement so cam doesn't go over players head
        mouseY = SYS_Help.ClampAngle(mouseY, y_minLimit, y_maxLimit);


        //Cam Zoom with mouse wheel
        if ((Input.GetAxis("Mouse ScrollWheel") < -deadZone) || (Input.GetAxis("Mouse ScrollWheel") > deadZone))
        {
            desiredDistance = Mathf.Clamp(
                distance - Input.GetAxis("Mouse ScrollWheel") * zoomSpeed,
                distanceMin,
                distanceMax);
            preOccludedDist = desiredDistance;
            occlusionSmooth = distanceSmooth;
        }
    }
Ejemplo n.º 2
0
    //Checks for the nearest point from Camera to something occluding it
    float CheckCameraPoints(Vector3 from, Vector3 to)
    {
        var nearestDistance = -1f;          //Hasn't collided with anything

        //Compare if any camera rays are hitting something

        RaycastHit hitInfo;

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

        //Draw lines in the editor to visualize camera occlusion area
        Debug.DrawLine(from, to + transform.forward * -camera.nearClipPlane, Color.red);

        Debug.DrawLine(from, clipPlanePoints.UpperLeft);
        Debug.DrawLine(from, clipPlanePoints.UpperRight);
        Debug.DrawLine(from, clipPlanePoints.LowerLeft);
        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);

        //Do line casts to check if the camera area is colliding with anything (ignores Player and System tags)
        if (Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo) && (hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "System"))
        {
            nearestDistance = hitInfo.distance;
        }

        if (Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo) && (hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "System"))
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1)
            {
                nearestDistance = hitInfo.distance;
            }
        }

        if (Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo) && (hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "System"))
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1)
            {
                nearestDistance = hitInfo.distance;
            }
        }

        if (Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo) && (hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "System"))
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1)
            {
                nearestDistance = hitInfo.distance;
            }
        }

        if (Physics.Linecast(from, to + transform.forward * -camera.nearClipPlane, out hitInfo) && (hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "System"))
        {
            if (hitInfo.distance < nearestDistance || nearestDistance == -1)
            {
                nearestDistance = hitInfo.distance;
            }
        }


        return(nearestDistance);
    }