void UpdateInput() { Assert.IsNotNull(_pawn.controller); if (_pawn.playerController != null) { var input = _pawn.playerController.input; var characterInputs = new PlayerCharacterInputs { MoveAxisForward = (input.forward ? 1 : 0) - (input.back ? 1 : 0), MoveAxisRight = (input.right ? 1 : 0) - (input.left ? 1 : 0), JumpDown = input.jump, CameraRotation = Quaternion.AngleAxis(input.yaw, Vector3.up), CrouchDown = Input.GetKeyDown(KeyCode.C), // #todo CrouchUp = Input.GetKeyUp(KeyCode.C) }; _characterController.SetInputs(ref characterInputs); #if CLIENT if (isClient) { _pawn.playerController.input.worldPosition = transform.position; } #endif } #if SERVER if (isServer && _pawn.remotePlayerController != null) { // Snap to client position if close enough, else correct client var diff = _pawn.remotePlayerController.input.worldPosition - transform.position; if (diff.sqrMagnitude < 6) { _characterController.Motor.SetPosition(_pawn.remotePlayerController.input.worldPosition); } else { _pawn.remotePlayerController.input.worldPosition = transform.position; if (Time.time >= _nextClientPositionCorrectionTime) { _nextClientPositionCorrectionTime = Time.time + 0.2f; _playerControllerSystem.SendControllerResetPawnPosition(_pawn.remotePlayerController.connection, transform.position); } } } #endif var aiController = _pawn.controller as AIController; if (aiController != null) { var input = aiController.input; var characterInputs = new AICharacterInputs { MoveVector = input.moveVector, LookVector = input.lookVector, JumpDown = input.jump }; _characterController.SetInputs(ref characterInputs); } }
/// <summary> /// This is called every frame by the AI script in order to tell the character what its inputs are /// </summary> public void SetInputs(ref AICharacterInputs inputs) { _moveInputVector = inputs.MoveVector; _lookInputVector = inputs.LookVector; switch (CurrentCharacterState) { case CharacterState.Default: { // Jumping input if (inputs.JumpDown) { _timeSinceJumpRequested = 0f; _jumpRequested = true; } break; } } }