public void UpdateSound() { float currentSoundDirection = -1; JetpackBoundsState boundsState = GetJetpackBoundsState; switch (boundsState) { case JetpackBoundsState.TooLow: currentSoundDirection = 1; break; case JetpackBoundsState.Neutral: currentSoundDirection = GetJetpackUpInput ? 1 : -1; break; case JetpackBoundsState.TooHigh: currentSoundDirection = -1; break; } currentJetpackSoundTransitionCoeff = Mathf.Clamp(currentJetpackSoundTransitionCoeff + Time.deltaTime * currentSoundDirection, 0, jetpackSoundTransitionDuration); jetpackOnSoundSource.volume = maxJetpackOnVolume * (currentJetpackSoundTransitionCoeff / jetpackSoundTransitionDuration); if (currentSoundDirection < 0 && previousSoundDirection > 0) { jetpackOffSoundSource.volume = maxJetpackOffVolume * (currentJetpackSoundTransitionCoeff / jetpackSoundTransitionDuration); jetpackOffSoundSource.Play(); } previousSoundDirection = currentSoundDirection; }
public void UpdateJetpackValues(bool isJetpackInputDown) { if (!won) { switch (inUseVersion) { case JetpackVersion.Version1: #region V1 JetpackBoundsState boundsState = GetJetpackBoundsState; float currentMaxUpSpeed = jetpackMaxUpSpeed; float currentMaxDownSpeed = jetpackMaxDownSpeed; float currentVerticalAcceleration = 0; switch (boundsState) { case JetpackBoundsState.TooLow: float distanceFromLow = GetLowDistance; if (Mathf.Abs(distanceFromLow) > standByDistanceFromBottom) { currentVerticalAcceleration = outOfBoundsUpAcceleration; currentMaxUpSpeed = isJetpackInputDown ? currentMaxUpSpeed : outOfBoundsUpMaxSpeed; } else { currentVerticalAcceleration = isJetpackInputDown ? currentMaxUpSpeed : standByAcceleration * -Mathf.Sign(distanceFromLow); } break; case JetpackBoundsState.Neutral: currentVerticalAcceleration = isJetpackInputDown ? jetpackUpAcceleration : (currentJetpackVerticalSpeed > 0 ? jetpackGravityWhenGoingUp : jetpackGravityWhenGoingDown); break; case JetpackBoundsState.TooHigh: currentVerticalAcceleration = -outOfBoundsDownAcceleration; currentMaxDownSpeed = -outOfBoundsDownMaxSpeed; break; } currentJetpackVerticalSpeed = Mathf.Clamp(currentJetpackVerticalSpeed + currentVerticalAcceleration * Time.deltaTime, currentMaxDownSpeed, currentMaxUpSpeed); #endregion break; case JetpackVersion.Version2: break; } } else { float distanceFromFirstPersonCharacter = (thirdPersonController.transform.position.y + 3) - transform.position.y; float currentVerticalAcceleration = standByAcceleration * Mathf.Sign(distanceFromFirstPersonCharacter); if (Mathf.Sign(currentJetpackVerticalSpeed) != Mathf.Abs(distanceFromFirstPersonCharacter)) { currentVerticalAcceleration *= 3; } currentJetpackVerticalSpeed = Mathf.Clamp(currentJetpackVerticalSpeed + currentVerticalAcceleration * Time.deltaTime, jetpackMaxDownSpeed, jetpackMaxUpSpeed); } /*else * { * if (currentJetpackVerticalSpeed == 0) * return; * * float accelerationDirection = -Mathf.Sign(currentJetpackVerticalSpeed); * float min = accelerationDirection < 0 ? 0 : currentJetpackVerticalSpeed; * float max = accelerationDirection > 0 ? 0 : currentJetpackVerticalSpeed; * * print(accelerationDirection * gameOverDeceleration * Time.deltaTime); * currentJetpackVerticalSpeed = * Mathf.Clamp(currentJetpackVerticalSpeed + accelerationDirection * gameOverDeceleration * Time.deltaTime, min, max); * }*/ #region Manage Pitch float targetPitchValue = 0; if (currentJetpackVerticalSpeed > 0) { targetPitchValue = Mathf.Lerp(0, maxPitchWhenGoingUp, goingUpPitchCurve.Evaluate((Mathf.Abs(currentJetpackVerticalSpeed) / jetpackMaxUpSpeed) * pitchUpMultiplicator)); } else { targetPitchValue = Mathf.Lerp(0, -maxPitchWhenGoingDown, goingDownPitchCurve.Evaluate((Mathf.Abs(currentJetpackVerticalSpeed) / Mathf.Abs(jetpackMaxDownSpeed)) * pitchDownMultiplicator)); } #endregion currentPitch = Mathf.Lerp(currentPitch, targetPitchValue, pitchChangingCoeff); transform.rotation = Quaternion.Euler(currentPitch, 0, 0); UpdateSound(); }