private void HandlePlayerInput()
    {
        var deadZone = 0.01f;

        // If right mouse button is down, get mouse axis input.
        if (Input.GetMouseButton(1))
        {
            _thirdPersonCamera.MouseX += Input.GetAxis("Mouse X") * MouseXSensitivity;
            _thirdPersonCamera.MouseY -= Input.GetAxis("Mouse Y") * MouseYSensitivity;
        }

        // Clamp (limit) mouse Y rotation. Uses thirdPersonCameraHelper.cs.
        _thirdPersonCamera.MouseY = ThirdPerson_Helper.clampingAngle(_thirdPersonCamera.MouseY,
                                                                     _thirdPersonCamera.YMinLimit,
                                                                     _thirdPersonCamera.YMaxLimit
                                                                     );

        // Clamp (limit) mouse scroll wheel.
        if (Input.GetAxis("Mouse ScrollWheel") > deadZone || Input.GetAxis("Mouse ScrollWheel") < -deadZone)
        {
            _thirdPersonCamera.DesiredDistance = Mathf.Clamp(_thirdPersonCamera.Distance -
                                                             Input.GetAxis("Mouse ScrollWheel") *
                                                             MouseWheelSensitivity,
                                                             _thirdPersonCamera.DistanceMin,
                                                             _thirdPersonCamera.DistanceMax
                                                             );
            _thirdPersonCamera.PreOccludedDistance  = _thirdPersonCamera.DesiredDistance;
            _thirdPersonCamera.DistanceCameraSmooth = _thirdPersonCamera.DistanceSmooth;
        }
    }
    private void HandlePlayerInput()
    {
        float deadZone = 0.01f;

        // If right mouse button is down, get mouse axis input.
        if (Input.GetMouseButton(1))
        {
            thirdPersonCamera.mouseX += Input.GetAxis("Mouse X") * mouseXSensitivity;
            thirdPersonCamera.mouseY -= Input.GetAxis("Mouse Y") * mouseYSensitivity;
        }

        // Clamp (limit) mouse Y rotation. Uses thirdPersonCameraHelper.cs.
        thirdPersonCamera.mouseY = ThirdPerson_Helper.clampingAngle(thirdPersonCamera.mouseY,
                                                                    thirdPersonCamera.yMinLimit,
                                                                    thirdPersonCamera.yMaxLimit
                                                                    );

        // Clamp (limit) mouse scroll wheel.
        if (Input.GetAxis("Mouse ScrollWheel") > deadZone || Input.GetAxis("Mouse ScrollWheel") < -deadZone)
        {
            thirdPersonCamera.desiredDistance = Mathf.Clamp(thirdPersonCamera.distance -
                                                            Input.GetAxis("Mouse ScrollWheel") *
                                                            mouseWheelSensitivity,
                                                            thirdPersonCamera.distanceMin,
                                                            thirdPersonCamera.distanceMax
                                                            );
            thirdPersonCamera.preOccludedDistance  = thirdPersonCamera.desiredDistance;
            thirdPersonCamera.distanceCameraSmooth = thirdPersonCamera.distanceSmooth;
        }
    }
    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 #4
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 #5
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);
    }