//...
// RotationToTarget - 하드락인 경우 카메라가 바라봐야 할 방향
// ControlRotation - 플레이어 카메라가 실제로 바라보고 있는 방향
// 둘의 차를 구한다
const FRotator DeltaRotator {
FMath::Abs(FMath::UnwindDegrees(RotationToTarget.Pitch - ControlRotation.Pitch)),
FMath::Abs(FMath::UnwindDegrees(RotationToTarget.Yaw - ControlRotation.Yaw)),
FMath::Abs(FMath::UnwindDegrees(RotationToTarget.Roll - ControlRotation.Roll)),
};
// TargetRotation 초기화
// 즉, 카메라가 타겟을 향해 바라봐야 하는지 여부
// 락온을 걸지 않은 상태에서 최초 락온을 걸었을 때 타이밍을 잡기 위한 플래그
if (CameraBuffer.bInitTargetRotation)
{
CameraBuffer.TargetRotation = RotationToTarget;
CameraBuffer.bInitTargetRotation = false;
}
else
{
// ...
// DeltaRotator의 Pitch가 Tolerance 즉 임계값을 넘었거나,
// 계속 타겟을 추적 중인지 플래그 확인
if (DeltaRotator.Pitch > HardlockData.PitchSleepTorlerance || CameraBuffer.bTraceTargetPitch)
{
// Pitch에 대해서만 업데이트하여 Pitch 값은 타겟을 추적하도록 허용
CameraBuffer.TargetRotation.Pitch = RotationToTarget.Pitch;
// PitchSleepTolerance와 SafePitchTolerance의 비교가 합당하지 않으면 실제로 추적을 하지 않는다
// SafePitchTolerance - 추적을 완료했다고 판단하는 Pitch 값
// PitchSleepTolerance - 이 수치보다 높으면 카메라가 타겟 추적을 시작
// 즉, 필수적으로 SafePitchTolerance의 값은 PitchSleepTolerance보다 작아야 한다 (ensure로 처리하는 게 좋았을 듯)
const bool bValidPitchComparizon = HardlockData.PitchSleepTolerance > HardlockData.SafePitchTolerance;
// Delta가 SafeAngularTolerance 미만인지 확인
// 즉, Pitch 추적이 "완료"되지 않았다면 계속 추적
CameraBuffer.bTraceTargetPitch = DeltaRotator.Pitch > HardLockData.SafePitchTolerance && bValidPitchComparison;
// ...
// Yaw에 대해서도 동일한 처리가 필요하다면 위의 코드와 똑같이 처리해준다
// 더 이상 추적하지 않아도 된다면
if (CameraBuffer.bTraceTargetPitch == false)
{
// 추적을 종료되면 플래그 초기화
CameraBuffer.bInitRotationSpeed = true;
}
}
}
// 최총 TargetRotation 할당
TargetRotation = CameraBuffer.TargetRotation;