Beispiel #1
0
        void Start()
        {
            //MySetupLocalPlayer ();

            this.StartForDamage();
            m_weaponHolder = GetComponent <WeaponHolder>();
        }
Beispiel #2
0
        void Awake()
        {
            if (null == Instance)
            {
                Instance      = this;
                IsLocalPlayer = true;
            }

            characterController = GetComponent <CharacterController>();
            m_weaponHolder      = GetComponent <WeaponHolder> ();
        }
Beispiel #3
0
        void Awake()
        {
            if (null == Instance)
            {
                Instance      = this;
                IsLocalPlayer = true;
            }

            characterController = GetComponent <CharacterController>();
            m_weaponHolder      = GetComponent <WeaponHolder> ();

            this.States = this.GetComponentsInChildren <Peds.States.BaseScriptState> ();

            this.AwakeForDamage();
        }
Beispiel #4
0
        //     protected override void OnAwake()
        protected void Awake()
        {
            //    base.OnAwake();

            Instance = this;

            characterController = GetComponent <CharacterController>();
            m_weaponHolder      = GetComponent <WeaponHolder> ();

            IsLocalPlayer = true;

            // Only debug

            //foreach (var go in gameObject.GetComponentsInChildren<Component>())
            //    Debug.LogFormat("Name: {0} => {1}", go.name, go.hideFlags);

            Debug.LogFormat("Shader level: {0}", SystemInfo.graphicsShaderLevel);

            Debug.LogFormat("Max FPS: {0}", Application.targetFrameRate);

            StartCoroutine(GPUAdjust());
        }
Beispiel #5
0
        private void UpdateCamera()
        {
            if (GameManager.CanPlayerReadInput())
            {
                // rotate camera

                var mouseDelta = new Vector2(Input.GetAxisRaw("Mouse X"), Input.GetAxisRaw("Mouse Y"));

                mouseDelta = Vector2.Scale(mouseDelta, CursorSensitivity);


                if (m_doSmooth)
                {
                    _smoothMouse.x = Mathf.Lerp(_smoothMouse.x, mouseDelta.x, 1f / smoothing.x);
                    _smoothMouse.y = Mathf.Lerp(_smoothMouse.y, mouseDelta.y, 1f / smoothing.y);

                    _mouseAbsolute += _smoothMouse;
                }
                else
                {
                    _mouseAbsolute += mouseDelta;
                }

                // Waiting for an answer: https://stackoverflow.com/questions/50837685/camera-global-rotation-clamping-issue-unity3d

                /*if (clampInDegrees.x > 0)
                 * _mouseAbsolute.x = Mathf.Clamp(_mouseAbsolute.x, -clampInDegrees.x, clampInDegrees.x);*/

                if (clampInDegrees.y > 0)
                {
                    _mouseAbsolute.y = Mathf.Clamp(_mouseAbsolute.y, -clampInDegrees.y, clampInDegrees.y);
                }


//				Vector3 eulers = Camera.transform.eulerAngles;
//				eulers.x += - mouseDelta.y;
//				eulers.y += mouseDelta.x;
//
//				// no rotation around z axis
//				eulers.z = 0;
//
//				// clamp rotation
//				if(eulers.x > 180)
//					eulers.x -= 360;
//				eulers.x = Mathf.Clamp (eulers.x, -clampInDegrees.x, clampInDegrees.x);
//
//				// apply new rotation
//				Camera.transform.eulerAngles = eulers;
            }

            Camera.transform.rotation = Quaternion.AngleAxis(_mouseAbsolute.x, Vector3.up)
                                        * Quaternion.AngleAxis(-_mouseAbsolute.y, Vector3.right);


            // this must be called from here (right after the camera transform is changed), otherwise camera will shake
            WeaponHolder.RotatePlayerInDirectionOfAiming();


            // cast a ray from player to camera to see if it hits anything
            // if so, then move the camera to hit point

            float   distance;
            Vector3 castFrom;
            Vector3 castDir = -Camera.transform.forward;

            float scrollValue = Input.mouseScrollDelta.y;

            if (!GameManager.CanPlayerReadInput())
            {
                scrollValue = 0;
            }

            if (IsInVehicle)
            {
                CarCameraDistance = Mathf.Clamp(CarCameraDistance - scrollValue, 2.0f, 32.0f);
                distance          = CarCameraDistance;
                castFrom          = CameraFocusPosVehicle;
                // cast towards current camera position
                //	castDir = (Camera.transform.position - castFrom).normalized;
            }
            else if (IsAiming)
            {
                castFrom = CameraFocusPos;

                // use distance from gun aiming offset ?
                if (CurrentWeapon.GunAimingOffset != null)
                {
                    //	Vector3 desiredCameraPos = this.transform.TransformPoint (- _player.CurrentWeapon.GunAimingOffset.Aim) + Vector3.up * .5f;
                    //	Vector3 desiredCameraPos = this.transform.TransformPoint( new Vector3(0.8f, 1.0f, -1) );
                    Vector3 desiredCameraPos = CameraFocusPos + Camera.transform.TransformVector(WeaponHolder.cameraAimOffset);
                    Vector3 diff             = desiredCameraPos - castFrom;
                    distance = diff.magnitude;
                    castDir  = diff.normalized;
                }
                else
                {
                    distance = PlayerCameraDistance;
                }
            }
            else
            {
                PlayerCameraDistance = Mathf.Clamp(PlayerCameraDistance - scrollValue, 2.0f, 32.0f);
                distance             = PlayerCameraDistance;
                castFrom             = this.CameraFocusPos;
            }

            var castRay = new Ray(castFrom, castDir);

            RaycastHit hitInfo;

            if (Physics.SphereCast(castRay, 0.25f, out hitInfo, distance,
                                   -1 ^ (1 << MapObject.BreakableLayer) ^ (1 << Vehicle.Layer)))
            {
                distance = hitInfo.distance;
            }

            Camera.transform.position = castRay.GetPoint(distance);
        }