private void HandleSprint() { // Handles sprinting and its effects. Currently still applies if the player is midair. // The second check ensures that the player does not start sprinting if less than a minimum threshold, // but that if it already was sprinting it can continue to do so. if (Input.GetKey(KeyCode.LeftShift) && !lockSprint && (playerStatistics.IsSprinting || playerStatistics.CanStartSprinting())) { currentSpeed = sprintSpeed; if (input.magnitude != 0) // If the player is moving { // Adds the sprint only to the forward direction Vector3 forwardMovement = Vector3.Project(input, transform.forward); Vector3 sideMovement = input - forwardMovement; forwardMovement *= sprintSpeed / regularSpeed; input = forwardMovement + sideMovement; // Updates camera position to match animation cameraAdjuster.SetSprintPosition(); // Updates item position to avoid visual shearing if (equipped != null) { equipped.SetSprint(); } else { equipped = GameObject.FindGameObjectWithTag("ItemHoldPoint").GetComponentInChildren <SprintAdjuster>(); } playerStatistics.IsSprinting = true; } else // Resets camera position if the player is no longer moving and sprinting { cameraAdjuster.ResetCameraPosition(); if (equipped != null) { equipped.SetNormal(); } else { equipped = GameObject.FindGameObjectWithTag("ItemHoldPoint").GetComponentInChildren <SprintAdjuster>(); } playerStatistics.IsSprinting = false; } } else { currentSpeed = regularSpeed; cameraAdjuster.ResetCameraPosition(); if (equipped != null) { equipped.SetNormal(); } else { equipped = GameObject.FindGameObjectWithTag("ItemHoldPoint").GetComponentInChildren <SprintAdjuster>(); } playerStatistics.IsSprinting = false; // Prevents player from holding down shift and sprinting as soon as stamina regens. if (Input.GetKey(KeyCode.LeftShift)) { lockSprint = true; } } // Unlocks sprint if it is locked and player releases shift. if (lockSprint && Input.GetKeyUp(KeyCode.LeftShift)) { lockSprint = false; } }