コード例 #1
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.GetButtonDown("Jump");
            characterInputs.CrouchDown      = Input.GetButtonDown("Fire1");
            characterInputs.CrouchUp        = Input.GetButtonUp("Fire1");

            // Apply inputs to character
            Character.SetInputs(ref characterInputs);
        }
コード例 #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.LeftControl);
            characterInputs.CrouchUp        = Input.GetKeyUp(KeyCode.LeftControl);

            // Apply inputs to character
            Character.SetInputs(ref characterInputs);
        }
コード例 #3
0
        /// <summary>
        /// This is called every frame by ExamplePlayer in order to tell the character what its inputs are
        /// </summary>
        public void SetInputs(ref PlayerCharacterInputs inputs)
        {
            // Clamp input
            Vector3 moveInputVector = Vector3.ClampMagnitude(new Vector3(inputs.MoveAxisRight, 0f, inputs.MoveAxisForward), 1f);

            // Calculate camera direction and rotation on the character plane
            Vector3 cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.forward, Motor.CharacterUp).normalized;

            if (cameraPlanarDirection.sqrMagnitude == 0f)
            {
                cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.up, Motor.CharacterUp).normalized;
            }
            Quaternion cameraPlanarRotation = Quaternion.LookRotation(cameraPlanarDirection, Motor.CharacterUp);

            axisYAnim = inputs.MoveAxisForward;
            axisHAnim = inputs.MoveAxisRight;
            anim.SetBool("onGround", onGround);

            switch (CurrentCharacterState)
            {
            case CharacterState.Default:
            {
                if (sinked == false)
                {
                    // Move and look inputs
                    _moveInputVector = cameraPlanarRotation * moveInputVector;

                    switch (OrientationMethod)
                    {
                    case OrientationMethod.TowardsCamera:
                        _lookInputVector = cameraPlanarDirection;
                        break;

                    case OrientationMethod.TowardsMovement:
                        _lookInputVector = _moveInputVector.normalized;
                        break;
                    }

                    // Jumping input
                    if (Input.GetButtonDown("A"))
                    {
                        _timeSinceJumpRequested = 0f;
                        _jumpRequested          = true;
                    }

                    // Crouching input
                    if (inputs.CrouchDown)
                    {
                        _shouldBeCrouching = true;

                        if (!_isCrouching)
                        {
                            _isCrouching = true;
                            Motor.SetCapsuleDimensions(0.5f, 1f, 0.5f);
                            MeshRoot.localScale = new Vector3(1f, 0.5f, 1f);
                        }
                    }
                    else if (inputs.CrouchUp)
                    {
                        _shouldBeCrouching = false;
                    }
                }
                break;
            }
            }
        }
        /// <summary>
        /// This is called every frame by ExamplePlayer in order to tell the character what its inputs are
        /// </summary>
        public void SetInputs(ref PlayerCharacterInputs inputs)
        {
            // Clamp input
            Vector3 moveInputVector = Vector3.ClampMagnitude(new Vector3(inputs.MoveAxisRight, 0f, inputs.MoveAxisForward), 1f);

            // Calculate camera direction and rotation on the character plane
            Vector3 cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.forward, Motor.CharacterUp).normalized;

            if (cameraPlanarDirection.sqrMagnitude == 0f)
            {
                cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.up, Motor.CharacterUp).normalized;
            }
            Quaternion cameraPlanarRotation = Quaternion.LookRotation(cameraPlanarDirection, Motor.CharacterUp);

            switch (CurrentCharacterState)
            {
            case CharacterState.Default:
            {
                // Move and look inputs
                _moveInputVector = cameraPlanarRotation * moveInputVector;

                if (_moveInputVector != Vector3.zero)
                {
                    /*if (FootstepSound != null)
                     * {
                     *  FootstepSound.HandleEvent(gameObject);
                     * }*/
                }

                switch (OrientationMethod)
                {
                case OrientationMethod.TowardsCamera:
                    _lookInputVector = cameraPlanarDirection;
                    break;

                case OrientationMethod.TowardsMovement:
                    _lookInputVector = _moveInputVector.normalized;
                    break;
                }

                // Jumping input
                if (inputs.JumpDown)
                {
                    _timeSinceJumpRequested = 0f;
                    _jumpRequested          = true;
                }

                // Crouching input
                if (inputs.CrouchDown)
                {
                    return;

                    _shouldBeCrouching = true;

                    if (!_isCrouching)
                    {
                        _isCrouching = true;
                        Motor.SetCapsuleDimensions(0.5f, 1f, 0.5f);
                        MeshRoot.localScale = new Vector3(1f, 0.5f, 1f);
                    }
                }
                else if (inputs.CrouchUp)
                {
                    return;

                    _shouldBeCrouching = false;
                }

                break;
            }
            }
        }
コード例 #5
0
        /// <summary>
        /// This is called every frame by ExamplePlayer in order to tell the character what its inputs are
        /// </summary>
        public void SetInputs(ref PlayerCharacterInputs inputs)
        {
            // Clamp input
            Vector3 moveInputVector = Vector3.ClampMagnitude(new Vector3(inputs.MoveAxisRight, 0f, inputs.MoveAxisForward), 1f);

            // Calculate camera direction and rotation on the character plane
            Vector3 cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.forward, Motor.CharacterUp).normalized;

            if (cameraPlanarDirection.sqrMagnitude == 0f)
            {
                cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.up, Motor.CharacterUp).normalized;
            }
            Quaternion cameraPlanarRotation = Quaternion.LookRotation(cameraPlanarDirection, Motor.CharacterUp);

            switch (CurrentCharacterState)
            {
            case CharacterState.Default:
            {
                // Move and look inputs
                _moveInputVector = cameraPlanarRotation * moveInputVector;

                switch (OrientationMethod)
                {
                case OrientationMethod.TowardsCamera:
                    _lookInputVector = cameraPlanarDirection;
                    break;

                case OrientationMethod.TowardsMovement:
                    _lookInputVector = _moveInputVector.normalized;
                    break;
                }

                // Jumping input
                if (inputs.JumpDown)
                {
                    _timeSinceJumpRequested = 0f;
                    _jumpRequested          = true;
                }

                // Crouching input
                if (inputs.CrouchDown && _moveInputVector.sqrMagnitude == 0f)
                {
                    _shouldBeCrouching = true;

                    if (!_isCrouching)
                    {
                        _isCrouching = true;
                        Motor.SetCapsuleDimensions(0.5f, CrouchedCapsuleHeight, CrouchedCapsuleHeight * 0.5f);
                        MeshRoot.localScale = new Vector3(1f, 0.5f, 1f);
                    }
                }
                else if (inputs.CrouchDown && _moveInputVector.sqrMagnitude > 0f)
                {
                    _shouldBeSliding = true;

                    if (!_isSliding)
                    {
                        _isSliding = true;
                        Motor.SetCapsuleDimensions(0.5f, CrouchedCapsuleHeight, CrouchedCapsuleHeight * 0.5f);
                        MeshRoot.localScale       = new Vector3(2f, 0.25f, 2f);
                        slopeAngle                = Motor.MaxStableSlopeAngle;
                        Motor.MaxStableSlopeAngle = 0f;
                    }
                }
                else if (inputs.CrouchUp)
                {
                    _shouldBeCrouching = false;
                    _shouldBeSliding   = false;
                }

                break;
            }
            }
        }
コード例 #6
0
        /// <summary>
        /// This is called every frame by ExamplePlayer in order to tell the character what its inputs are
        /// </summary>
        public void SetInputs(ref PlayerCharacterInputs inputs)
        {
            // Clamp input
            Vector3 moveInputVector = Vector3.ClampMagnitude(new Vector3(inputs.MoveAxisRight, 0f, inputs.MoveAxisForward), 1f);

            // Calculate camera direction and rotation on the character plane
            Vector3 cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.forward, Motor.CharacterUp).normalized;

            if (cameraPlanarDirection.sqrMagnitude == 0f)
            {
                cameraPlanarDirection = Vector3.ProjectOnPlane(inputs.CameraRotation * Vector3.up, Motor.CharacterUp).normalized;
            }
            Quaternion cameraPlanarRotation = Quaternion.LookRotation(cameraPlanarDirection, Motor.CharacterUp);

            switch (CurrentCharacterState)
            {
            case CharacterState.Default:
            {
                // Move and look inputs
                _moveInputVector = cameraPlanarRotation * moveInputVector;

                switch (OrientationMethod)
                {
                case OrientationMethod.TowardsCamera:
                    _lookInputVector = cameraPlanarDirection;
                    break;

                case OrientationMethod.TowardsMovement:
                    _lookInputVector = _moveInputVector.normalized;
                    break;
                }

                // Jumping input
                if (inputs.JumpDown)
                {
                    _timeSinceJumpRequested = 0f;
                    _jumpRequested          = true;
                }

                //Commented out crouching input since it gave an unreachable code warning

                // Crouching input

                /*if (inputs.CrouchDown)
                 * {
                 *  return;
                 *  //_shouldBeCrouching = true;
                 *
                 *  if (!_isCrouching)
                 *  {
                 *      _isCrouching = true;
                 *      Motor.SetCapsuleDimensions(0.5f, 1f, 0.5f);
                 *      MeshRoot.localScale = new Vector3(1f, 0.5f, 1f);
                 *  }
                 * }
                 * else if (inputs.CrouchUp)
                 * {
                 *  return;
                 *  //_shouldBeCrouching = false;
                 * }*/

                break;
            }
            }
        }