Esempio n. 1
0
        private void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Cursor.lockState = CursorLockMode.Locked;
            }

            // Gather input
            float moveAxisForward    = Input.GetAxisRaw("Vertical");
            float moveAxisRight      = Input.GetAxisRaw("Horizontal");
            float mouseLookAxisUp    = Input.GetAxisRaw("Mouse Y");
            float mouseLookAxisRight = Input.GetAxisRaw("Mouse X");

            _moveInputVector = new Vector3(moveAxisRight, 0f, moveAxisForward);
            _moveInputVector = Vector3.ClampMagnitude(_moveInputVector, 1f);

            // Apply mouse sensitivity
            _lookInputVector = new Vector3(mouseLookAxisRight * MouseSensitivity, mouseLookAxisUp * MouseSensitivity, 0f);

            if (Cursor.lockState != CursorLockMode.Locked)
            {
                //_lookInputVector = Vector3.zero;
            }

            if (Character && OrbitCamera)
            {
                // Apply move input to character
                Vector3 cameraOrientedInput = Quaternion.LookRotation(OrbitCamera.PlanarDirection, OrbitCamera.transform.up) * _moveInputVector;
                Character.SetInputs(cameraOrientedInput, OrbitCamera.PlanarDirection);

                // Jump input
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    Character.Jump();
                }

                // Croucing input
                if (Input.GetKeyDown(KeyCode.C))
                {
                    Character.Crouch(true);
                }
                else if (Input.GetKeyUp(KeyCode.C))
                {
                    Character.Crouch(false);
                }

                // Apply input to camera
                float scrollInput = -Input.GetAxis("Mouse ScrollWheel");
#if UNITY_WEBGL
                scrollInput = 0f;
#endif
                OrbitCamera.SetInputs(scrollInput, _lookInputVector);

                if (Input.GetMouseButtonDown(1))
                {
                    OrbitCamera.TargetDistance = (OrbitCamera.TargetDistance == 0f) ? OrbitCamera.DefaultDistance : 0f;
                }
            }
        }
Esempio n. 2
0
        private void HandleCharacterInput()
        {
            PlayerCharacterInputs characterInputs = new PlayerCharacterInputs();

            // Build the CharacterInputs struct
            characterInputs.MoveAxisForward = Input.GetAxisRaw(VerticalInput);
            characterInputs.MoveAxisRight   = Input.GetAxisRaw(HorizontalInput);
            characterInputs.CameraRotation  = CharacterCamera.Transform.rotation;
            characterInputs.JumpDown        = Input.GetKeyDown(KeyCode.Space);
            characterInputs.CrouchDown      = Input.GetKeyDown(KeyCode.C);
            characterInputs.CrouchUp        = Input.GetKeyUp(KeyCode.C);

            // Apply inputs to character
            Character.SetInputs(ref characterInputs);
        }