fix: Aiming through cover kinda works thank god

This commit is contained in:
NeonDmn 2025-06-01 15:57:17 +02:00
parent a75cc548a7
commit f3567a115e
6 changed files with 24 additions and 15 deletions

Binary file not shown.

View File

@ -91,7 +91,7 @@ void AExoPlayerCharacter::Tick(float DeltaTime)
//////////////////////////
UpdateCameraHeight(DeltaTime);
//ApplyCameraOffset(DeltaTime);
ApplyCameraOffsets(DeltaTime);
}
float AExoPlayerCharacter::GetFootOffset()
@ -108,15 +108,17 @@ void AExoPlayerCharacter::UpdateCameraHeight(float DeltaTime)
const float NewHeight = FMath::Lerp(GetCurrentEyeHeight(), TargetEyeHeight, DeltaTime*5);
const FVector CamRelXY = CameraComponent->GetRelativeLocation();
CameraComponent->SetRelativeLocation(FVector(CamRelXY.X, CamRelXY.Y,
GetFootOffset() + NewHeight));
EyeHeight = GetFootOffset() + NewHeight;
CameraComponent->SetRelativeLocation(FVector(CamRelXY.X, CamRelXY.Y,EyeHeight));
}
void AExoPlayerCharacter::ApplyCameraOffset(float DeltaTime)
void AExoPlayerCharacter::ApplyCameraOffsets(float DeltaTime)
{
bool HasChanged = false;
//FVector NewOffset = EyeLocationOffset;
//FVector NoOffsetCameraPosition = FVector(0, 0, EyeHeight);
//FVector NoOffsetCameraPosition = CameraComponent->GetRelativeLocation() - EyeLocationOffset;
//UE_LOG(LogTemp, Log, TEXT("%s"), *NoOffsetCameraPosition.ToString());
if (!FVector::PointsAreNear(EyeLocationOffset, TargetEyeLocationOffset, 0.01f))
{
@ -128,7 +130,7 @@ void AExoPlayerCharacter::ApplyCameraOffset(float DeltaTime)
if (!FMath::IsNearlyEqual(EyeRoll, TargetEyeRoll, 0.01f))
{
// Smoothly rotate view
EyeRoll = FMath::Lerp(EyeRoll, TargetEyeRoll, DeltaTime);
EyeRoll = FMath::Lerp(EyeRoll, TargetEyeRoll, DeltaTime*5);
HasChanged = true;
}
@ -143,9 +145,11 @@ void AExoPlayerCharacter::ApplyCameraOffset(float DeltaTime)
//CameraComponent->SetRelativeLocation(NoOffsetCameraPosition + NewOffset);
//FVector CapsuleRelativeOffset = BaseLocation + EyeLocationOffset;
//CapsuleRelativeOffset.Z += GetCurrentEyeHeightBase(true);
CameraComponent->SetRelativeLocation(EyeLocationOffset);
const FVector FinalOffset = FVector(EyeLocationOffset.X, EyeLocationOffset.Y,
EyeLocationOffset.Z + TargetEyeHeight + GetFootOffset());
CameraComponent->SetRelativeLocation(FinalOffset);
UE_LOG(LogTemp, Log, TEXT("Camera relative: %s"), *CameraComponent->GetRelativeLocation().ToString());
//UE_LOG(LogTemp, Log, TEXT("Camera relative: %s"), *CameraComponent->GetRelativeLocation().ToString());
// Update actual camera rotation (Roll)
FRotator NewRotator = GetController()->GetControlRotation();
NewRotator.Roll = EyeRoll;

View File

@ -370,8 +370,8 @@ float AExoPlayerController::CalculateCoverAimOffset()
return 0.f;
}
// Oblicz maksymalną wysokość na którą można wychylić się z nad osłony
MaxCoverAimHeightOffset = PlayerCharacter->GetStandingEyeHeight() * CoverAimStandFactor;
// Oblicz maksymalną wysokość, na którą można wychylić się znad osłony
MaxCoverAimHeight = PlayerCharacter->GetStandingEyeHeight() * CoverAimStandFactor;
FVector ObstacleTraceStart = GetCharacter()->GetActorLocation();
ObstacleTraceStart.Z +=
@ -421,9 +421,12 @@ float AExoPlayerController::CalculateCoverAimOffset()
// }
// }
ObstacleTraceStart = PlayerCharacter->GetPlayerLocationAtFeet();
ObstacleTraceStart.Z += PlayerCharacter->CrouchedEyeHeight;
ObstacleTraceEnd = ObstacleTraceStart + PlayerCameraManager->GetCameraRotation().Vector() * CoverAimFreeDistance;
float SafeCoverAimZOffset = 0.f;
while (SafeCoverAimZOffset < MaxCoverAimHeightOffset)
while (SafeCoverAimZOffset < MaxCoverAimHeight)
{
ObstacleTraceStart.Z += SafeCoverAimZOffset;
ObstacleTraceEnd.Z += SafeCoverAimZOffset;
@ -449,9 +452,10 @@ float AExoPlayerController::CalculateCoverAimOffset()
break;
}
}
const float FinalHitHeight = Hit.TraceStart.Z - PlayerCharacter->GetPlayerLocationAtFeet().Z;
// If this is true that means that free space was found
if (SafeCoverAimZOffset <= MaxCoverAimHeightOffset)
if (FinalHitHeight <= MaxCoverAimHeight)
{
//// DEBUG ////
if (bShowCoverSystemDebug)
@ -460,7 +464,7 @@ float AExoPlayerController::CalculateCoverAimOffset()
}
//////////////
return SafeCoverAimZOffset;// +
return FinalHitHeight - PlayerCharacter->CrouchedEyeHeight;// +
//PlayerCharacter->CrouchedEyeHeight - PlayerCharacter->GetCurrentEyeHeight();
}

View File

@ -156,7 +156,8 @@ private:
float EyeRoll;
float TargetEyeHeight;
float EyeHeight;
void UpdateCameraHeight(float DeltaTime);
void ApplyCameraOffset(float DeltaTime);
void ApplyCameraOffsets(float DeltaTime);
};

View File

@ -238,7 +238,7 @@ private:
float CoverStandAlpha = 0.0f; // deprecated
FTimerHandle CoverCheckTimer;
float MaxCoverAimHeightOffset;
float MaxCoverAimHeight;
float CoverAimHeightOffset;