/// <summary> /// Set the isSprinting bool and manage the Sprint Behavior /// </summary> /// <param name="value"></param> public virtual void Sprint(bool value) { var sprintConditions = (currentStamina > 0 && hasMovementInput && isGrounded && !customAction && !(isStrafing && !strafeSpeed.walkByDefault && (horizontalSpeed >= 0.5 || horizontalSpeed <= -0.5 || verticalSpeed <= 0.1f) && !sprintOnlyFree)); if (value && sprintConditions) { if (currentStamina > (finishStaminaOnSprint ? sprintStamina : 0) && hasMovementInput) { finishStaminaOnSprint = false; if (isGrounded && useContinuousSprint) { isCrouching = false; isSprinting = !isSprinting; if (isSprinting) { OnStartSprinting.Invoke(); } else { OnFinishSprinting.Invoke(); } } else if (!isSprinting) { OnStartSprinting.Invoke(); isSprinting = true; } } else if (!useContinuousSprint && isSprinting) { if (currentStamina <= 0) { finishStaminaOnSprint = true; OnFinishSprintingByStamina.Invoke(); } isSprinting = false; OnFinishSprinting.Invoke(); } } else if (isSprinting && (!useContinuousSprint || !sprintConditions)) { if (currentStamina <= 0) { finishStaminaOnSprint = true; OnFinishSprintingByStamina.Invoke(); } isSprinting = false; OnFinishSprinting.Invoke(); } }
public virtual void Sprint(bool value) { var sprintConditions = (currentStamina > 0 && input.sqrMagnitude > 0.1f && !isCrouching && isGrounded && !customAction && !(isStrafing && !strafeSpeed.walkByDefault && (direction >= 0.5 || direction <= -0.5 || speed <= 0))); if (value && sprintConditions) { if (currentStamina > (finishStaminaOnSprint ? sprintStamina : 0) && input.sqrMagnitude > 0.1f) { finishStaminaOnSprint = false; if (isGrounded && !isCrouching && useContinuousSprint) { isSprinting = !isSprinting; OnStartSprinting.Invoke(); } else if (!isSprinting) { isSprinting = true; } } else if (!useContinuousSprint && isSprinting) { if (currentStamina <= 0) { finishStaminaOnSprint = true; OnFinishSprintingByStamina.Invoke(); } isSprinting = false; OnFinishSprinting.Invoke(); } } else if (isSprinting && (!useContinuousSprint || !sprintConditions)) { if (currentStamina <= 0) { finishStaminaOnSprint = true; OnFinishSprintingByStamina.Invoke(); } isSprinting = false; OnFinishSprinting.Invoke(); } }