So it used to work, and now it doesn’t. What is meant to happen when I sprint is it is meant to increase the FOV gradually but now it wont. Here is the code related to stamina and sprint zoom.
private void Update()
{
if (CanMove)
{
HandleMovementInput();
HandleMouseLook();
if (canJump)
{
HandleJump();
}
if (canZoom)
{
HandleZoom();
}
if (useStamina)
{
HandleStamina();
}
if (canCrouch)
{
HandleCrouch();
}
if (canUseHeadbob)
{
HandleHeadBob();
}
if (canSprintZoom)
{
HandleSprintZoom();
}
if (canInteract)
{
HandleInteractionCheck();
HandleInteractionInput();
}
//if (canVault)
//{
// HandleVault();
//}
//if (canClimb)
//{
// HandleClimb();
//}
//if(useFootsteps)
//Handle_FootSteps();
ApplyFinalMovement();
}
}
public void HandleMovementInput()
{
currentInput = new Vector2((isCrouching ? crouchSpeed : IsSprinting ? sprintSpeed : walkSpeed) * Input.GetAxis("Vertical"), (isCrouching ? crouchSpeed : IsSprinting ? sprintSpeed : walkSpeed) * Input.GetAxis("Horizontal"));
float moveDirectionY = moveDirection.y;
moveDirection = (transform.TransformDirection(Vector3.forward) * currentInput.x) + (transform.TransformDirection(Vector3.right) * currentInput.y);
moveDirection.y = moveDirectionY;
}
public void HandleStamina()
{
if (currentStamina < minStamina)
{
currentStamina = minStamina;
OnStaminaChange?.Invoke(currentStamina);
}
if (Input.GetButtonDown("Jump") && currentStamina > minStamina)
{
currentStamina -= 10f;
OnStaminaChange?.Invoke(currentStamina);
if (regeneratingStamina != null)
{
StopCoroutine(regeneratingStamina);
regeneratingStamina = null;
}
}
if(IsSprinting && currentInput != Vector2.zero && isCrouching == false && !duringCrouchAnimation && currentStamina > minStamina)
{
if(regeneratingStamina != null)
{
StopCoroutine(regeneratingStamina);
regeneratingStamina = null;
}
currentStamina -= staminaUseMultiplier * Time.deltaTime;
if (currentStamina < minStamina)
currentStamina = minStamina;
OnStaminaChange?.Invoke(currentStamina);
if (currentStamina <= minStamina)
{
canSprint = false;
canJump = false;
}
if (currentStamina <= 20 && currentStamina != minStamina)
{
timeBeforeStaminaRegenStarts = 5f;
}
else if (currentStamina <= minStamina)
{
timeBeforeStaminaRegenStarts = 7f;
}
else if (currentStamina > 20)
{
timeBeforeStaminaRegenStarts = 3f;
}
}
if(!IsSprinting && currentStamina < maxStamina && regeneratingStamina == null)
{
regeneratingStamina = StartCoroutine(RegenerateStamina());
}
}
public void HandleSprintZoom()
{
if (Input.GetButtonDown("Sprint") && currentInput != Vector2.zero && !isCrouching && !duringCrouchAnimation && currentStamina !<= minStamina)
{
if(sprintZoomRoutine != null)
{
StopCoroutine(sprintZoomRoutine);
sprintZoomRoutine = null;
Debug.Log("Zoom Start");
}
sprintZoomRoutine = StartCoroutine(SprintZoom(true));
}
if (Input.GetButtonUp("Sprint"))
{
if (sprintZoomRoutine != null)
{
StopCoroutine(sprintZoomRoutine);
sprintZoomRoutine = null;
Debug.Log("Zoom End");
}
sprintZoomRoutine = StartCoroutine(SprintZoom(false));
}
}
public IEnumerator SprintZoom(bool isEnter)
{
float SprintTargetFOV = isEnter ? SprintZoomFOV : defaultFOV;
float StartingFOV = playerCamera.fieldOfView;
float timeElapsed = 0;
while(timeElapsed < sprintTimeToZoom)
{
playerCamera.fieldOfView = Mathf.Lerp(StartingFOV, SprintTargetFOV, timeElapsed / timeToZoom);
timeElapsed += Time.deltaTime;
yield return null;
}
playerCamera.fieldOfView = SprintTargetFOV;
sprintZoomRoutine = null;
}
And some other problems, watch the 1 to see the rest.