private void WalkRun() { // Input var hInput = Input.GetAxis("Horizontal"); var vInput = Input.GetAxis("Vertical"); movement = new Vector3(hInput, 0, vInput); // Sprint var speedModifier = 1f; if (Input.GetButton("Sprint") && stamina.value > 0) { speedModifier = sprintModifier; stamina.AddToValue(-Time.deltaTime); } // Move Player movement = Vector3.ClampMagnitude(movement, 1); movement *= moveSpeed * speedModifier; // Rotate Player if (movement.magnitude > 0) { var rotation = Quaternion.LookRotation(movement.normalized); rotation = Quaternion.Lerp(transform.rotation, rotation, rotateSpeed * Time.deltaTime); transform.rotation = rotation; } }
private IEnumerator Sprint() { isRunning = true; // Sprinting Speed speedModifier = sprintModifier; // Deplete Stamina while (Input.GetButton("Sprint") && stamina.value > 0) { if (!godMode) { stamina.AddToValue(-Time.fixedDeltaTime); } yield return(new WaitForFixedUpdate()); } // Stop Sprinting isRunning = false; if (stamina.value > 0) { // Regular Speed speedModifier = 1f; yield return(new WaitForSeconds(1f)); } else { // Slow Speed staminaCoolingDown = true; speedModifier = slowModifier; yield return(new WaitForSeconds(2f)); } // Regenerate Stamina while (!stamina.IsMaxed) { stamina.AddToValue(Time.fixedDeltaTime); yield return(new WaitForFixedUpdate()); } // End speedModifier = 1f; staminaCoolingDown = false; }