private IEnumerator RotateAroundPivotAnimation(float angleToRotate, Vector3 pivot) { var currentlyRotatedAngle = 0f; var finishedRotating = false; while (!finishedRotating) { var deltaAngle = Time.deltaTime * _movementSpeed * Mathf.Sign(angleToRotate); transform.position = UtilitiesER.RotatePointAroundPivot(transform.position, pivot, Quaternion.AngleAxis(deltaAngle, Vector3.up)); currentlyRotatedAngle += deltaAngle; transform.LookAt(pivot); if (angleToRotate > 0 && currentlyRotatedAngle >= angleToRotate) { finishedRotating = true; } else if (angleToRotate < 0 && currentlyRotatedAngle <= angleToRotate) { finishedRotating = true; } yield return(null); } _rotationMovementCoroutine = null; }
private void FetchScores() { var currentTime = Time.realtimeSinceStartup; _scoreDamageTaken = Mathf.Clamp(_scorePotentialDamageTaken - (_redirectionManager._playerManager._numberOfHitsTaken * _scoreLossPerDamageTaken), 0, _scorePotentialDamageTaken); _scoreQuizAnswers = Mathf.Clamp(_quizManager._numberOfCorrectAnswers * (_scorePotentialQuizAnswers / _quizManager._correctnessDisplays.Count), 0, _scorePotentialQuizAnswers); _scoreTime = Mathf.Clamp(_scorePotentialTime - (int)UtilitiesER.Remap(0, _maximumTimeInMinutes * 60f, 0, _scorePotentialTime, currentTime - _startTime), 0, _scorePotentialTime); var finalScore = _scoreDamageTaken + _scoreTime + _scoreQuizAnswers; _scoreText.text = "Score(<color=#00ff00ff>Time Taken</color>):\n" + _scoreTime + "\n" + "Score(<color=#ff0000ff>Damage Taken</color>):\n" + _scoreDamageTaken + "\n" + "Score(<color=#a52a2aff>Quiz Answers</color>):\n" + _scoreQuizAnswers + "\n" + "Score(<color=#ffa500ff>Total</color>):\n" + finalScore; _leaderboardText.text = "Participant ID:\n" + _experimentDataManager._currentParticipantId + "\nScore Placement:\n" + FindScorePlacement(finalScore) + "/" + (_experimentDataManager._previousGameScores.Count + 1); var newGameData = new IngameScoreData(); newGameData._id = _experimentDataManager._currentParticipantId; newGameData._damageScore = _scoreDamageTaken; newGameData._quizScore = _scoreQuizAnswers; newGameData._timeScore = _scoreTime; newGameData._totalScore = finalScore; _experimentDataManager.FinishDataRecording(newGameData); }
private void Update() { if (_gameManager._debugMode && (Input.GetKeyDown(KeyCode.P) || (SteamVR.active && SteamVR_Actions._default.GrabGrip.GetStateDown(_batonHand)))) { AddCharge(100); } if (_gameManager._debugMode && (Input.GetKeyDown(KeyCode.X) || (SteamVR_Actions._default.GrabGrip.GetStateDown(_shieldHand)))) { AddEXP(100); } if (_currentCharge >= _maxBatonCharge) { if (Input.GetKeyDown(KeyCode.Space) || (SteamVR.active && SteamVR_Actions._default.GrabPinch.GetStateDown(_batonHand))) { Shoot(); return; } _chargedAnimationTimer += Time.deltaTime * _chargedAnimationSpeed; var sineTimer = UtilitiesER.Remap(-1f, 1f, 0, 1, Mathf.Sin(_chargedAnimationTimer)); // +1 is added to these calculations so the emission strength is a bit more noticeable _batonRenderer.material.SetColor("_EmissionColor", Color.Lerp(Color.black * 0, _currentEmissionColor, sineTimer)); } }
public void ResetCharge() { _currentCharge = 0f; var remappedValue = UtilitiesER.Remap(0, _maxBatonCharge, 0, 1, _currentCharge); _batonRenderer.material.SetColor("_EmissionColor", new Color(remappedValue, remappedValue, remappedValue, 1.0f) * (remappedValue + 1)); }
private void MoveBehindPlayer() { transform.position = UtilitiesER.RotatePointAroundPivot(transform.position, _targetTransform.position, Quaternion.AngleAxis(-Time.deltaTime * _movementSpeed, _orbitAxis)); if (transform.position.y < _startPosition.y) { _targetReached = true; _movementSpeed *= _movementScaleAfterRotation; } }
private void Update() { if (!_translating) { return; } _lerpTimer += Time.deltaTime * _movementSpeed; transform.Rotate(_rotationAxis, Time.deltaTime * _rotationSpeed); transform.position = UtilitiesER.GetPointOnBezierCurve ( _startPosition, _startPosition + (_anchorOffset / 2), _targetTransform.position + _anchorOffset, _targetTransform.position, _lerpTimer ); }
protected IEnumerator DisplayHealth() { var targetFill = UtilitiesER.Remap(0, _maxHealth, 0, 1, _health); var initialFill = _healthBarFillImage.fillAmount; var healthAnimationTimer = 0f; while (healthAnimationTimer <= _healthBarDisplayDuration) { yield return(null); healthAnimationTimer += Time.deltaTime; _healthBarFillImage.fillAmount = Mathf.Lerp(initialFill, targetFill, healthAnimationTimer * 2f); _healthBarTransform.localScale = Vector3.one * _healthBarScaleDuringAnimation.Evaluate(UtilitiesER.Remap(0, _healthBarDisplayDuration, 0, 1, healthAnimationTimer)); } _healthBarTransform.localScale = Vector3.zero; _healthBarFillImage.fillAmount = targetFill; }
public void AddCharge(float amount, bool playAudio = true) { _currentCharge = Mathf.Clamp(amount + _currentCharge, 0, _maxBatonCharge); if (_currentCharge < _maxBatonCharge) { var remappedValue = UtilitiesER.Remap(0, _maxBatonCharge, 0, 1, _currentCharge); _batonRenderer.material.SetColor("_EmissionColor", Color.Lerp(Color.black * 0, _currentEmissionColor, remappedValue)); } else { _chargedAnimationTimer = 0f; _batonLineRenderer.enabled = true; if (playAudio) { _audioSource.PlayOneShot(_batonChargedSound, 0.7f); } } }
public void CheckForPhaseChange() { var phaseChanged = false; foreach (var phase in _phases) { if (phase.IsWithinPhaseThreshold(UtilitiesER.Remap(0, _maxHealth, 0, 100, _health)) && phase != _currentPhase) { _currentPhase = phase; _attackOrderIndex = 0; _attackTimer = _currentPhase._attackCooldown; if (_currentPhase._usesPhaseTransitionAnimation) { _animatedInterface.AnimationTriggerWithCallback("PhaseTransition", RestartAttacking); phaseChanged = true; } } } if (!phaseChanged) { RestartAttacking(); } }
private void Update() { if (!_translating) { return; } _spawnAnimationTimer += Time.deltaTime * _spawnAnimationSpeed; _spawnerTransform.localScale = Vector3.Lerp(Vector3.zero, Vector3.one, _spawnAnimationTimer); _movementTimer += Time.deltaTime; _spawnerTransform.localPosition = Vector3.Lerp(_startPosition, _startPosition - Vector3.right * _startPosition.x * 2, UtilitiesER.Remap(0, _cooldownBetweenShots * (_numberOfProjectiles + 1), 0, 1, _movementTimer)); _timer += Time.deltaTime; if (_timer >= _cooldownBetweenShots) { _timer -= _cooldownBetweenShots; _numberOfShotProjectiles++; var newProjectileObject = Instantiate(_projectilePrefab, _spawnerTransform.position, Quaternion.identity); var projectileSettings = newProjectileObject.GetComponent <BasicProjectile>(); projectileSettings.Initialise(_attackSettings, _targetTransform, _projectileSpeedMultiplier); _audioSource.PlayOneShot(_attackSettings._spawnAudio, _attackSettings._spawnAudioScale); } if (_numberOfShotProjectiles > _numberOfProjectiles) { Destroy(); } }
private void GenerateRandomTimeStep() { _currentTimestep = _timeStepBase + UtilitiesER.Remap(0, 1, -_timeStepNoise, _timeStepNoise, (float)Randoms.NextDouble()); }
private void IncrementGains() { // The upper bound is exclusive while the lower is inclusive. // Curvature radius can not be changed as long as AC2F is active. var gainChoice = Randoms.Next(0, (_experimentDataManager._redirectionManager._currentActiveRedirectionAlgorithmType == RedirectionAlgorithms.AC2F) ? 2 : 3); var newGain = 0f; if (gainChoice == 0) { newGain = Mathf.Clamp(_experimentDataManager._redirectionManager.MIN_ROT_GAIN - _rotationGainBaseIncrement + UtilitiesER.Remap(0, 1, -_rotationGainIncrementNoise, _rotationGainIncrementNoise, (float)Randoms.NextDouble()), _maximumNegativeGain, 0); _experimentDataManager._redirectionManager.MIN_ROT_GAIN = newGain; } else if (gainChoice == 1) { newGain = Mathf.Clamp(_experimentDataManager._redirectionManager.MAX_ROT_GAIN + _rotationGainBaseIncrement + UtilitiesER.Remap(0, 1, -_rotationGainIncrementNoise, _rotationGainIncrementNoise, (float)Randoms.NextDouble()), 0, _maximumPositiveGain); _experimentDataManager._redirectionManager.MAX_ROT_GAIN = newGain; } else { newGain = Mathf.Clamp(_experimentDataManager._redirectionManager.CURVATURE_RADIUS - _curvatureRadiusBaseIncrement + UtilitiesER.Remap(0, 1, -_curvatureRadiusIncrementNoise, _curvatureRadiusIncrementNoise, (float)Randoms.NextDouble()), _minimumCurvatureRadius, 1000); _experimentDataManager._redirectionManager.CURVATURE_RADIUS = newGain; } }