diff --git a/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset b/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset index f295766..35df021 100644 Binary files a/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset and b/Content/Blueprints/Characters/Player/BP_ExoPlayerCharacter.uasset differ diff --git a/Content/Levels/TestMap.umap b/Content/Levels/TestMap.umap index 8f81ca9..7b13708 100644 Binary files a/Content/Levels/TestMap.umap and b/Content/Levels/TestMap.umap differ diff --git a/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp b/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp index 1b0e232..7e57e0e 100644 --- a/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp +++ b/Source/Exo/Private/Characters/ExoPlayerCharacter.cpp @@ -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; diff --git a/Source/Exo/Private/Player/ExoPlayerController.cpp b/Source/Exo/Private/Player/ExoPlayerController.cpp index 5a8c7cd..f064663 100644 --- a/Source/Exo/Private/Player/ExoPlayerController.cpp +++ b/Source/Exo/Private/Player/ExoPlayerController.cpp @@ -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(); } diff --git a/Source/Exo/Public/Characters/ExoPlayerCharacter.h b/Source/Exo/Public/Characters/ExoPlayerCharacter.h index 02a4a0e..ab82e26 100644 --- a/Source/Exo/Public/Characters/ExoPlayerCharacter.h +++ b/Source/Exo/Public/Characters/ExoPlayerCharacter.h @@ -156,7 +156,8 @@ private: float EyeRoll; float TargetEyeHeight; + float EyeHeight; void UpdateCameraHeight(float DeltaTime); - void ApplyCameraOffset(float DeltaTime); + void ApplyCameraOffsets(float DeltaTime); }; diff --git a/Source/Exo/Public/Player/ExoPlayerController.h b/Source/Exo/Public/Player/ExoPlayerController.h index 017f0fb..edfe266 100644 --- a/Source/Exo/Public/Player/ExoPlayerController.h +++ b/Source/Exo/Public/Player/ExoPlayerController.h @@ -238,7 +238,7 @@ private: float CoverStandAlpha = 0.0f; // deprecated FTimerHandle CoverCheckTimer; - float MaxCoverAimHeightOffset; + float MaxCoverAimHeight; float CoverAimHeightOffset;