Esempio n. 1
0
    void TouchMouse()
    {
        // Get looking joy
        joyLook = ControllerHub.GetControllerTouch("TouchArea").GetAxis();

        // unmark this code and region "Smooth Rotation" if you use your Touch controller and want smooth rotation
        // ControllerHub.GetControllerTouch controller has own implementation for smoothing
        //SmoothedTouchMouseValues();
    }
Esempio n. 2
0
    private void Update()
    {
        //******************** show  how to Controllers values for your code
        // Joy Values
        JoyAxisRaw            = ControllerHub.GetControllerJoy("JoyArea").GetAxis(); // .GetAxis("Raw");
        JoyAxisNormalized     = ControllerHub.GetControllerJoy("JoyArea").GetAxis("Normalized");
        JoyAxisWalkRun        = ControllerHub.GetControllerJoy("JoyArea").GetAxis("WalkRun");
        JoyAxisFourDirections = ControllerHub.GetControllerJoy("JoyArea").GetAxis("Four");

        JoyTouched = ControllerHub.GetControllerJoy("JoyArea").GetControllerInTouch();

        // Joy Values
        //Joy1AxisRaw = ControllerHub.GetControllerJoy("JoyArea (1)").GetAxis(); // .GetAxis("Raw");
        //Joy1Touched = ControllerHub.GetControllerJoy("JoyArea (1)").GetControllerInTouch();
        // Touch Values
        TouchAxis    = ControllerHub.GetControllerTouch("TouchArea").GetAxis();
        TouchTouched = ControllerHub.GetControllerTouch("TouchArea").GetControllerInTouch();
    }
Esempio n. 3
0
    /*
     * [Tooltip("camera rotation with Lerp")]
     * [SerializeField] private bool smoothRotation = true;
     * private Vector3 joyLookPrevious = new Vector2();
     *
     * /// <summary>
     * /// If you want to add smooth to rotation
     * /// </summary>
     * void SmoothedTouchMouseValues()
     * {
     *  if (smoothRotation && (joyLook.x == 0 || joyLook.z == 0))
     *  {
     *      joyLook = Vector3.Lerp(joyLookPrevious, joyLook, Time.deltaTime * 10);
     *      joyLookPrevious = joyLook;
     *  }
     * }
     */
    #endregion

    void ZoomButtonsMouseWheel()
    {
        // Get zoom. Need to also get zoom from on screen controls
        joyZoom = ControllerHub.GetControllerTouch("TouchArea").GetMouseWheel();

        joyZoom = BtnZooming();

        if (joyZoom > 0)
        {
            joyZoom += zoomStep;
        }
        if (joyZoom < 0)
        {
            joyZoom -= zoomStep;
        }
        zoomFromController += joyZoom;

        zoomFromController = Mathf.Clamp(zoomFromController, zoomMax, zoomMin);
    }
Esempio n. 4
0
    void CameraMoveUpdateThirdPersonFocused()
    {
        if (bodyTransform == null)
        {
            return;
        }
        bodyPos = bodyTransform.position;

        bool _joyLookTouched = ControllerHub.GetControllerTouch("TouchArea").GetControllerInTouch();
        bool _autoLook       = false;

        if (!_joyLookTouched)//поиск цели, или слежение за целью
        {
            Vector3 _bodyPosOffsetted = new Vector3(bodyOffsetThirdPerson.x, bodyOffsetThirdPerson.y, 0) + bodyPos;

            float _distance = targettingDistance + Vector3.Distance(camTransform.position, _bodyPosOffsetted); // distance to the target to enable focusing
            Ray   _ray      = new Ray(camTransform.position, camTransform.forward);

            RaycastHit _hit;
            if (Physics.Raycast(_ray, out _hit, _distance))
            {
                if ((Vector3.Distance(bodyPos, _hit.point) <= targettingDistance) && (TagInFocuseList(_hit.transform.gameObject.tag)))
                {
                    targetObjectTransform = _hit.transform;
                }
            }

            //If target persist and distance to target is ok then ok, else remove target
            if ((targetObjectTransform != null) && (Vector3.Distance(bodyPos, targetObjectTransform.position) > targettingDistance))
            {
                targetObjectTransform = null;
            }

            if (targetObjectTransform != null)
            {
                _autoLook = true;

                // // // // SemiWorkedTPCF(Vector3 bodyPos)

                //Vector3 _dirBodToTarget = (targetObjectTransform.position - bodyPos);
                Vector3 _dirCamToTarget = (targetObjectTransform.position - camTransform.position);

                //Vector3 _dirRotated = Vector3.RotateTowards(camTransform.forward, _dirBodToTarget, Vector3.Angle(camTransform.forward, _dirBodToTarget), 0.01f);

                Quaternion _rotation = Quaternion.LookRotation(_dirCamToTarget, camTransform.up);
                //Quaternion _rotation = Quaternion.LookRotation(_dirBodToTarget);
                //Quaternion _rotation = Quaternion.LookRotation(_dirRotated);

                zoomNow = ZoomNow();
                Vector3 position = _rotation * new Vector3(bodyOffsetThirdPerson.x, bodyOffsetThirdPerson.y, zoomNow) + bodyPos;
                //Vector3 position = _rotation * new Vector3(xEuler, bodyOffsetThirdPerson.y, zoomNow) + bodyPos;


                //position = Clamp_Colision(bodyPos, position);
                camTransform.position = position;
                camTransform.rotation = Quaternion.LookRotation(targetObjectTransform.position - camTransform.position);
            }
        }
        else
        {
            targetObjectTransform = null;
        }

        if (!_autoLook)
        {
            CameraMoveUpdateThirdPerson();
        }
    }
Esempio n. 5
0
    void CameraMoveTestMethod3()
    {
        if (bodyTransform == null)
        {
            return;
        }
        bodyPos = bodyTransform.position;

        bool _joyLookTouched = ControllerHub.GetControllerTouch("TouchArea").GetControllerInTouch();
        bool _autoLook       = false;

        if (!_joyLookTouched)//поиск цели, или слежение за целью
        {
            Vector3 _bodyPosOffsettedY = new Vector3(0, bodyOffsetThirdPerson.y, 0) + bodyPos;

            float _distance = targettingDistance + Vector3.Distance(camTransform.position, _bodyPosOffsettedY); // distance to the target to enable focusing
            Ray   _ray      = new Ray(camTransform.position, camTransform.forward);

            RaycastHit _hit;
            if (Physics.Raycast(_ray, out _hit, _distance))
            {
                if ((Vector3.Distance(bodyPos, _hit.point) <= targettingDistance) && (TagInFocuseList(_hit.transform.gameObject.tag)))
                {
                    targetObjectTransform = _hit.transform;
                }
            }

            //If target persist and distance to target is ok then ok, else remove target
            if ((targetObjectTransform != null) && (Vector3.Distance(bodyPos, targetObjectTransform.position) > targettingDistance))
            {
                targetObjectTransform = null;
            }

            if (targetObjectTransform != null)
            {
                /**************************************
                 * Vector3 side = Vector3.Cross (direction, Vector3.up)
                 * Vector3 up = Vector3.Cross (direction, side)
                 *************************************/
                _autoLook = true;

                Vector3 _dirBodyToTarg         = targetObjectTransform.position - bodyPos;
                Vector3 _targetPosVirtualPoint = targetObjectTransform.position;

                distanceBodyToTarget = Vector3.Distance(bodyPos, targetObjectTransform.position);
                // если обьект ближе этого расстояния, то точку слежения отдаляю на разницу
                float _closeLimit = 4;
                if (distanceBodyToTarget < _closeLimit)//2.83
                {
                    _targetPosVirtualPoint = _targetPosVirtualPoint + (_dirBodyToTarg).normalized * (_closeLimit - distanceBodyToTarget);
                }
                gismoTPCred = _targetPosVirtualPoint;
                // получаю желаемый поворот в эулерах (градусах)
                Vector3 _rotationEuler = Quaternion.LookRotation(_targetPosVirtualPoint - camTransform.position).eulerAngles;

                // получаю градусы между текущим вектором форвард камеры и вектором на таргет

                // получаю направление довотора вектора ???

                // клами поворота
                // float xEuler = Clamp_xEuler(camTransform.eulerAngles.x + joyLook.y);
                xEuler = Clamp_xEuler(_rotationEuler.x);



                // доворачиваю вектор форвард камеры на этот градус, в направлении на таргет
                // Quaternion rotation = Quaternion.Euler(xEuler, camTransform.eulerAngles.y + joyLook.x, 0f);
                Quaternion rotation = Quaternion.Euler(xEuler, _rotationEuler.y, 0f);
                //Quaternion rotation = Quaternion.Euler(xEuler, camTransform.eulerAngles.y, 0f);
                //Quaternion rotation = Quaternion.Euler(camTransform.eulerAngles.x, _rotationEuler.y, 0f);     // нет отслеживания по вертикали
                //Quaternion rotation = Quaternion.Euler(_rotationEuler.x, _rotationEuler.y, 0f); // нет клампа по вертикали

                zoomNow = ZoomNow();

                Vector3 position = rotation * new Vector3(bodyOffsetThirdPerson.x, bodyOffsetThirdPerson.y, zoomNow) + bodyPos;

                //position = Clamp_Colision(bodyPos, position);

                // считаю положение второй раз, если коллизии с перерасчетом на коллизии
                position = rotation * Clamp_CollisionOffset(bodyPos, position) + bodyPos;

                camTransform.rotation = rotation;
                camTransform.position = position;
            }
        }
        else
        {
            targetObjectTransform = null;
        }

        if (!_autoLook)
        {
            CameraMoveUpdateThirdPerson();
        }
    }
Esempio n. 6
0
    // TPCF по вектору от цели ищем положение с офсетом на теле
    void CameraMoveTestMethod2()
    {
        if (bodyTransform == null)
        {
            return;
        }
        bodyPos = bodyTransform.position;

        bool _joyLookTouched = ControllerHub.GetControllerTouch("TouchArea").GetControllerInTouch();
        bool _autoLook       = false;

        if (!_joyLookTouched)//поиск цели, или слежение за целью
        {
            Vector3 _bodyPosOffsettedY = new Vector3(0, bodyOffsetThirdPerson.y, 0) + bodyPos;

            float _distance = targettingDistance + Vector3.Distance(camTransform.position, _bodyPosOffsettedY); // distance to the target to enable focusing
            Ray   _ray      = new Ray(camTransform.position, camTransform.forward);

            RaycastHit _hit;
            if (Physics.Raycast(_ray, out _hit, _distance))
            {
                if ((Vector3.Distance(bodyPos, _hit.point) <= targettingDistance) && (TagInFocuseList(_hit.transform.gameObject.tag)))
                {
                    targetObjectTransform = _hit.transform;
                }
            }

            //If target persist and distance to target is ok then ok, else remove target
            if ((targetObjectTransform != null) && (Vector3.Distance(bodyPos, targetObjectTransform.position) > targettingDistance))
            {
                targetObjectTransform = null;
            }

            if (targetObjectTransform != null)
            {
                /**************************************
                 * Vector3 side = Vector3.Cross (direction, Vector3.up)
                 * Vector3 up = Vector3.Cross (direction, side)
                 *************************************/
                _autoLook = true;

                float _disBodyToTarg = Vector3.Distance(_bodyPosOffsettedY, targetObjectTransform.position);

                //Vector3 _dirCamToTarget = (targetObjectTransform.position - camTransform.position).normalized;
                Vector3 _dirBodyToTarget = (targetObjectTransform.position - _bodyPosOffsettedY).normalized;

                Vector3 _dirTargToBody = (bodyPos - targetObjectTransform.position);
                Vector3 _right         = Vector3.Cross(_dirTargToBody, Vector3.up).normalized;
                // Vector3 _up = Vector3.Cross(_dirBodyToTarget, _right).normalized;
                Vector3 _up          = Vector3.Cross(-_dirTargToBody, _right).normalized;
                Vector3 _offsetedPos = bodyPos + _right * bodyOffsetThirdPerson.x + _up * bodyOffsetThirdPerson.y + _dirTargToBody.normalized * -ZoomNow();

                Debug.DrawRay(bodyPos, _right, Color.red);
                Debug.DrawRay(bodyPos, _up, Color.yellow);

                //Vector3 _ToTargetForC

                Vector3 _targetGismoPoint = _bodyPosOffsettedY + (_dirBodyToTarget * (_disBodyToTarg + 2));// targettingDistance;

                Quaternion rotation = Quaternion.LookRotation(targetObjectTransform.position - _offsetedPos);


                camTransform.rotation = rotation;
                camTransform.position = _offsetedPos;

                gismoTPCyellow = _targetGismoPoint;
                gismoTPCred    = _offsetedPos;
            }
        }
        else
        {
            targetObjectTransform = null;
        }

        if (!_autoLook)
        {
            CameraMoveUpdateThirdPerson();
        }
    }
Esempio n. 7
0
    // камера не глючит, если цель возле тела, но дрожит, если цель далеко. Вращается по градусам
    void CameraMoveTestMethod()
    {
        if (bodyTransform == null)
        {
            return;
        }
        bodyPos = bodyTransform.position;

        bool _joyLookTouched = ControllerHub.GetControllerTouch("TouchArea").GetControllerInTouch();
        bool _autoLook       = false;

        if (!_joyLookTouched)//поиск цели, или слежение за целью
        {
            Vector3 _bodyPosOffsettedY = new Vector3(0, bodyOffsetThirdPerson.y, 0) + bodyPos;

            float _distance = targettingDistance + Vector3.Distance(camTransform.position, _bodyPosOffsettedY); // distance to the target to enable focusing
            Ray   _ray      = new Ray(camTransform.position, camTransform.forward);

            RaycastHit _hit;
            if (Physics.Raycast(_ray, out _hit, _distance))
            {
                if ((Vector3.Distance(bodyPos, _hit.point) <= targettingDistance) && (TagInFocuseList(_hit.transform.gameObject.tag)))
                {
                    targetObjectTransform = _hit.transform;
                }
            }

            //If target persist and distance to target is ok then ok, else remove target
            if ((targetObjectTransform != null) && (Vector3.Distance(bodyPos, targetObjectTransform.position) > targettingDistance))
            {
                targetObjectTransform = null;
            }

            if (targetObjectTransform != null)
            {
                _autoLook = true;
                //Vector3 _dirBodToTarget = (targetObjectTransform.position - bodyPos);
                Vector3 _dirCamToTarget  = (targetObjectTransform.position - camTransform.position);
                Vector3 _dirCamToTargetN = _dirCamToTarget.normalized;
                Vector3 _dirCamForw      = camTransform.forward;

                float _distCamToTarg = Vector3.Distance(camTransform.position, targetObjectTransform.position);

                angle = Vector3.Angle(_dirCamForw, _dirCamToTarget.normalized);

                Vector3 pointProjection = camTransform.position + camTransform.forward * _distCamToTarg;
                gismoCamPos       = pointProjection;
                gismoBodyOfsetPos = _bodyPosOffsettedY;
                float _distCamToProjection = Vector3.Distance(camTransform.position, pointProjection);

                _directProjectionToTarg = (targetObjectTransform.position - pointProjection);


                Debug.DrawRay(pointProjection, _directProjectionToTarg, Color.blue);
                Debug.DrawRay(camTransform.position, _dirCamToTargetN * (_distCamToTarg + 2), Color.red);
                Debug.DrawRay(camTransform.position, camTransform.forward * (_distCamToTarg + 2), Color.yellow);

                screenProjecPoint = gameObject.GetComponent <Camera>().WorldToScreenPoint(pointProjection);
                screenTargetPoint = gameObject.GetComponent <Camera>().WorldToScreenPoint(targetObjectTransform.position);
                screenBodyPoint   = gameObject.GetComponent <Camera>().WorldToScreenPoint(_bodyPosOffsettedY);

                Vector3 directionScrenProfectToTarget = (screenTargetPoint - screenProjecPoint).normalized;

                angleBody = -Vector2.Angle(screenProjecPoint - screenBodyPoint, Vector2.right);

                joyEmulator.y = -directionScrenProfectToTarget.y;
                joyEmulator.x = directionScrenProfectToTarget.x;

                // поворот вектора на градус (крестовина ординат меняется от + к х)
                //if (_distCamToTarg < _distCamToProjection)
                joyEmulator.x = RotateVector(joyEmulator, angleBody).x; // применяю по х поворот

                // для опытов ограничиваю один из векторов
                if (!readX)
                {
                    joyEmulator.x = 0;
                }
                if (!readY)
                {
                    joyEmulator.y = 0;
                }



                float xEuler = Clamp_xEuler(camTransform.eulerAngles.x + joyEmulator.y);
                xEulerPublic = xEuler;

                Quaternion rotation = Quaternion.Euler(xEuler, camTransform.eulerAngles.y + joyEmulator.x, 0f);
                zoomNow = ZoomNow();

                Vector3 position = rotation * new Vector3(bodyOffsetThirdPerson.x, bodyOffsetThirdPerson.y, zoomNow) + bodyPos;
                position = Clamp_Colision(bodyPos, position);

                camTransform.rotation = rotation;
                camTransform.position = position;
            }
        }
        else
        {
            targetObjectTransform = null;
        }

        if (!_autoLook)
        {
            CameraMoveUpdateThirdPerson();
            gismoCamPos = camTransform.position;
        }
    }