/// <summary> /// Callback that happens whenever an active distractor has finished. /// This is mostly where cleanup happens. /// </summary> public void OnDistractorEnd() { // If AC2F managed to align the user, then we have to return to the gains that were used right before alignment. if (_alignmentComplete) { MAX_ROT_GAIN = _baseMaximumRotationGain; MIN_ROT_GAIN = _baseMinimumRotationGain; } _distractorIsActive = false; _distractorEndCallback?.Invoke(); _futureVirtualWalkingDirection = Vector3.zero; RequestAlgorithmSwitch(false); _currentActiveDistractor.FinaliseDistractor(); _currentActiveDistractor = null; _gameManager.StopBattleTheme(); _distractorCooldownMagnitudeAccumulation = 0f; }
/// <summary> /// Callback that happens whenever the user has moved outside of the safe area in the physical space. /// It initialises and spawns a distractor to help reorient the user back towards the centre of the physical space. /// </summary> public void OnDistractorTrigger() { if (!_distractorsEnabled || _distractorCooldownMagnitudeAccumulation <= _distractorMagnitudeCooldownAfterDeath) { return; } if (_distractorIsActive || !_gameManager._gameStarted) { return; } _distractorIsActive = true; _distractorTriggerCallback?.Invoke(); _alignmentComplete = false; var _averageFuture = Vector3.zero; for (int i = 0; i < _positionSamples.Size; i++) { _averageFuture += _positionSamples[i]; } _futureVirtualWalkingDirection = (_averageFuture / _positionSamples.Size).normalized; RequestAlgorithmSwitch(true); if (_debugDistractor != null) { _currentActiveDistractor = Instantiate(_debugDistractor).GetComponent <DistractorEnemy>(); } else { // This approach should allow for semi random distractor choices, which mostly avoids repeats of the same one. var chosenPrefab = _randomDistractorPoolList[Random.Range(0, _randomDistractorPoolList.Count)]; var newDistractor = Instantiate(chosenPrefab).GetComponent <DistractorEnemy>(); _currentActiveDistractor = newDistractor; _randomDistractorPoolList.Remove(chosenPrefab); if (_randomDistractorPoolList.Count == 0) { RepopulateRandomDistractorList(); } } _currentActiveDistractor.InitialiseDistractor(this); }