Source/FPS_Project/Private/FPS_Character.cpp
void AFPS_Character::SmoothCrouch(float DeltaTime) 
{

	
	//Crouch
	if (bIsCrouching && CurrentEyeHeight - CrouchRealEyeHeight > 0.f)  {

		CrouchAlpha += DeltaTime;
		CrouchAlpha = FMath::Clamp(CrouchAlpha, 0.f, CrouchTransitionTime); //Time Interval for zooming

		CrouchAlphaLerp = CrouchAlpha / CrouchTransitionTime;
		CrouchAlphaLerp = CrouchAlphaLerp * CrouchAlphaLerp ; //quadratic function for smoothness (x^2)


		CurrentEyeHeight = FMath::Lerp(BaseEyeHeight, CrouchRealEyeHeight, CrouchAlphaLerp); //Calculate FOV
		CameraComponent->SetRelativeLocation(FVector(CameraComponent->GetRelativeLocation().X, CameraComponent->GetRelativeLocation().Y, CurrentEyeHeight)); //Adjust FOV

		if (bIsSprinting) {
			SprintReleased();
		}

	}//Uncrouch
	else if (!bIsCrouching && BaseEyeHeight - CurrentEyeHeight > 0.f) {

		//Calculate interpolation alpha
		CrouchAlpha -= DeltaTime;
		CrouchAlpha = FMath::Clamp(CrouchAlpha,0.f, CrouchTransitionTime); //Time Interval for crouching

		CrouchAlphaLerp = CrouchAlpha / CrouchTransitionTime;
		CrouchAlphaLerp = CrouchAlphaLerp * CrouchAlphaLerp ; //quadratic function for smoothness (x^2)


		CurrentEyeHeight = FMath::Lerp(BaseEyeHeight, CrouchRealEyeHeight, CrouchAlphaLerp); //Calculate eye height
		CameraComponent->SetRelativeLocation(FVector(CameraComponent->GetRelativeLocation().X, CameraComponent->GetRelativeLocation().Y, CurrentEyeHeight)); //Adjust eye height
	}
}
//Calculate camera pos at Crouch/Uncrouch
Calculate camera pos at Crouch/Uncrouch
Calculate camera pos at Crouch / Uncrouch
void AFPS_Character::SmoothCrouch(float DeltaTime) 
{
	if (bIsCrouching && CurrentEyeHeight - CrouchRealEyeHeight > 0.f)  {
		CrouchAlpha += DeltaTime;
		CrouchAlpha = FMath::Clamp(CrouchAlpha, 0.f, CrouchTransitionTime); 
		CrouchAlphaLerp = CrouchAlpha / CrouchTransitionTime;
		CrouchAlphaLerp = CrouchAlphaLerp * CrouchAlphaLerp ; 
		CurrentEyeHeight = FMath::Lerp(BaseEyeHeight, CrouchRealEyeHeight, CrouchAlphaLerp); 
		CameraComponent->SetRelativeLocation(FVector(CameraComponent->GetRelativeLocation().X, CameraComponent->GetRelativeLocation().Y, CurrentEyeHeight)); 
		if (bIsSprinting) {
			SprintReleased();
		}
	}
	else if (!bIsCrouching && BaseEyeHeight - CurrentEyeHeight > 0.f) {
		CrouchAlpha -= DeltaTime;
		CrouchAlpha = FMath::Clamp(CrouchAlpha,0.f, CrouchTransitionTime); 
		CrouchAlphaLerp = CrouchAlpha / CrouchTransitionTime;
		CrouchAlphaLerp = CrouchAlphaLerp * CrouchAlphaLerp ; 
		CurrentEyeHeight = FMath::Lerp(BaseEyeHeight, CrouchRealEyeHeight, CrouchAlphaLerp); 
		CameraComponent->SetRelativeLocation(FVector(CameraComponent->GetRelativeLocation().X, CameraComponent->GetRelativeLocation().Y, CurrentEyeHeight)); 
	}
}
void AFPS_Character :: SmoothCrouch ( float DeltaTime ) { if ( bIsCrouching && CurrentEyeHeight - CrouchRealEyeHeight > 0.f ) { CrouchAlpha += DeltaTime ; CrouchAlpha = FMath :: Clamp ( CrouchAlpha , 0.f , CrouchTransitionTime ) ; CrouchAlphaLerp = CrouchAlpha / CrouchTransitionTime ; CrouchAlphaLerp = CrouchAlphaLerp * CrouchAlphaLerp ; CurrentEyeHeight = FMath :: Lerp ( BaseEyeHeight , CrouchRealEyeHeight , CrouchAlphaLerp ) ; CameraComponent -> SetRelativeLocation ( FVector ( CameraComponent -> GetRelativeLocation ( ) . X , CameraComponent -> GetRelativeLocation ( ) . Y , CurrentEyeHeight ) ) ; if ( bIsSprinting ) { SprintReleased ( ) ; } } else if ( ! bIsCrouching && BaseEyeHeight - CurrentEyeHeight > 0.f ) { CrouchAlpha -= DeltaTime ; CrouchAlpha = FMath :: Clamp ( CrouchAlpha , 0.f , CrouchTransitionTime ) ; CrouchAlphaLerp = CrouchAlpha / CrouchTransitionTime ; CrouchAlphaLerp = CrouchAlphaLerp * CrouchAlphaLerp ; CurrentEyeHeight = FMath :: Lerp ( BaseEyeHeight , CrouchRealEyeHeight , CrouchAlphaLerp ) ; CameraComponent -> SetRelativeLocation ( FVector ( CameraComponent -> GetRelativeLocation ( ) . X , CameraComponent -> GetRelativeLocation ( ) . Y , CurrentEyeHeight ) ) ; } }
Calculate camera pos at Crouch/Uncrouch
Calculate camera pos at Crouch / Uncrouch
//Crouch //Time Interval for zooming //quadratic function for smoothness (x^2) //Calculate FOV //Adjust FOV //Uncrouch //Calculate interpolation alpha //Time Interval for crouching //quadratic function for smoothness (x^2) //Calculate eye height //Adjust eye height