private void Start() { Cursor.lockState = CursorLockMode.Confined; Cursor.visible = false; Character = GameObject.FindWithTag("Player").GetComponent <KinPlayerController>(); characterInputs = new PlayerCharacterInputs { MoveAxisForward = 0.0f, JumpDown = false, CrouchDown = false, CrouchUp = false, InteractDown = false, EscapeDown = false, FireDown = false, }; }
/// <summary> /// This is called every frame in order to tell the character what its inputs are /// </summary> public void SetInputs(ref PlayerCharacterInputs inputs) { // Clamp input var moveInputVector = Vector3.ClampMagnitude(new Vector3(0f, 0f, inputs.MoveAxisForward), 1f); // Calculate camera direction and rotation on the character plane var cameraPlanarDirection = Vector3.ProjectOnPlane(Quaternion.identity * Vector3.forward, Motor.CharacterUp).normalized; if (Math.Abs(cameraPlanarDirection.sqrMagnitude) < 0.001) { cameraPlanarDirection = Vector3.ProjectOnPlane(Quaternion.identity * Vector3.up, Motor.CharacterUp).normalized; } var cameraPlanarRotation = Quaternion.LookRotation(cameraPlanarDirection, Motor.CharacterUp); switch (CurrentCharacterState) { case CharacterState.Default: { // Move and look inputs _moveInputVector = cameraPlanarRotation * moveInputVector; // Jumping input if (inputs.JumpDown) { _timeSinceJumpRequested = 0f; _jumpRequested = true; } if (inputs.InteractDown) { _timeSinceInteractRequested = 0f; _interactRequested = true; } if (inputs.FireDown) { _timeSinceFireRequested = 0f; _fireRequested = true; } if (inputs.EscapeDown) { _timeSinceEscapeRequested = 0f; _escapeRequested = true; } // Crouching input if (inputs.CrouchDown) { _shouldBeCrouching = true; if (!_isCrouching) { _isCrouching = true; Motor.SetCapsuleDimensions(0.25f, 0.85f, 0.425f); } } else if (inputs.CrouchUp) { _shouldBeCrouching = false; } break; } case CharacterState.Dying: { break; } case CharacterState.Revive: { break; } case CharacterState.Pause: { break; } } }