Compare commits

..

5 Commits

13 changed files with 439 additions and 233 deletions

View File

@ -63,3 +63,15 @@ ServerDefaultMap=/Engine/Maps/Entry.Entry
GlobalDefaultGameMode=/Game/Blueprints/Game/BP_ExoGameMode.BP_ExoGameMode_C
GlobalDefaultServerGameMode=None
[CoreRedirects]
+FunctionRedirects=(OldName="/Script/Exo.ExoPlayerController.UpdateCoverStandHeight",NewName="/Script/Exo.ExoPlayerController.UpdateSmoothCoverCamera")
+FunctionRedirects=(OldName="/Script/Exo.ExoPlayerController.AdjustCameraWhileInCover",NewName="/Script/Exo.ExoPlayerController.CalculateCoverAim")
+FunctionRedirects=(OldName="/Script/Exo.ExoPlayerController.SetNewCameraLocationOffset",NewName="/Script/Exo.ExoPlayerController.SetEyePositionOffset")
+FunctionRedirects=(OldName="/Script/Exo.ExoPlayerController.SetNewCameraRotationOffset",NewName="/Script/Exo.ExoPlayerController.SetEyeRoll")
+PropertyRedirects=(OldName="/Script/Exo.ExoPlayerCharacter.IsInCover",NewName="/Script/Exo.ExoPlayerCharacter.bIsInCover")
+PropertyRedirects=(OldName="/Script/Exo.ExoPlayerCharacter.CoverEyeHeight",NewName="/Script/Exo.ExoPlayerCharacter.LowEyeHeight")
+FunctionRedirects=(OldName="/Script/Exo.ExoPlayerController.CalculateCoverAim",NewName="/Script/Exo.ExoPlayerController.CalculateCoverAimOffset")
+PropertyRedirects=(OldName="/Script/Exo.ExoPlayerController.UseEyeHeight",NewName="/Script/Exo.ExoPlayerController.bUseEyeHeight")
+FunctionRedirects=(OldName="/Script/Exo.ExoPlayerCharacter.SetEyePositionOffset",NewName="/Script/Exo.ExoPlayerCharacter.SetEyePositionOffsetTarget")
+FunctionRedirects=(OldName="/Script/Exo.ExoPlayerCharacter.UnCrouchCustom",NewName="/Script/Exo.ExoPlayerCharacter.TryUnCrouchCustom")

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -265,6 +265,7 @@ void UShootingComponent::StartAiming()
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed * AimingMoveSpeedScale;
TargetFOV = CurrentGunBase->AimingFOV;
OnStartedADS.Broadcast();
}
}
@ -274,6 +275,8 @@ void UShootingComponent::StopAiming()
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed;
TargetFOV = DefaultFOV;
OnStoppedADS.Broadcast();
}
void UShootingComponent::Throw()

View File

@ -5,16 +5,29 @@
#include "Blueprint/UserWidget.h"
#include "Characters/Components/ShootingComponent.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Items/AmmoBoxBase.h"
#include "Items/HealthBoxBase.h"
#include "Kismet/GameplayStatics.h"
#include "Player/InteractionComponent.h"
#include "Widget/WBP_PlayerUI.h"
AExoPlayerCharacter::AExoPlayerCharacter()
{
PrimaryActorTick.bCanEverTick = true;
// Setup eye height values
StandingEyeHeight = 175.f;
CrouchedEyeHeight = 50.f;
LowEyeHeightOffset = -20.f;
// Create camera component
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
CameraComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
CameraComponent->bUsePawnControlRotation = true;
GetCharacterMovement()->bSnapToPlaneAtStart = true;
InteractionComponent = CreateDefaultSubobject<UInteractionComponent>(TEXT("Interaction Component"));
@ -30,21 +43,25 @@ AExoPlayerCharacter::AExoPlayerCharacter()
//bUseControllerRotationPitch = false;
//bUseControllerRotationYaw = true;
//bUseControllerRotationRoll = false;
// Setup camera component
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
CameraComponent->AttachToComponent(RootComponent, FAttachmentTransformRules::KeepRelativeTransform);
CameraComponent->bUsePawnControlRotation = true;
CameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, BaseEyeHeight));
}
void AExoPlayerCharacter::BeginPlay()
{
Super::BeginPlay();
// Set correct starting camera height
SetTargetEyeHeight(StandingEyeHeight);
CameraComponent->SetRelativeLocation(FVector(0.0f, 0.0f, TargetEyeHeight + GetFootOffset()));
GetCapsuleComponent()->OnComponentBeginOverlap.AddDynamic(this, &AExoPlayerCharacter::OnActorBeginOverlap);
//UGameplayStatics::GetPlayerCameraManager(GetWorld(), 0)->SetViewTarget(this);
StandingEyeHeight = CameraComponent->GetRelativeLocation().Z;
// Setup crouch timeline
FOnTimelineFloat ProgressUpdate;
ProgressUpdate.BindUFunction(this, FName("CrouchingUpdate"));
FOnTimelineEvent FinishedEvent;
FinishedEvent.BindUFunction(this, FName("CrouchingFinished"));
CrouchTimeline.AddInterpFloat(CapsuleResizeCurve, ProgressUpdate);
CrouchTimeline.SetTimelineFinishedFunc(FinishedEvent);
PlayerHud = CreateWidget<UWBP_PlayerUI>(GetWorld(),PlayerHudClass);
@ -64,8 +81,89 @@ void AExoPlayerCharacter::BeginPlay()
}
}
void AExoPlayerCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
CrouchTimeline.TickTimeline(2*DeltaTime);
UpdateCameraHeight(DeltaTime);
ApplyCameraOffsets(DeltaTime);
}
float AExoPlayerCharacter::GetFootOffset()
{
return -GetCapsuleComponent()->GetScaledCapsuleHalfHeight();
}
void AExoPlayerCharacter::CrouchingUpdate(float Alpha)
{
float CurrentCamHeight = GetCurrentEyeHeight();
float NewHalfHeight = FMath::Lerp(
StandingHalfHeight, GetCharacterMovement()->CrouchedHalfHeight, Alpha);
GetCapsuleComponent()->SetCapsuleHalfHeight(NewHalfHeight);
CameraComponent->SetRelativeLocation(
FVector(0, 0, GetFootOffset()) +
FVector(0, 0, CurrentCamHeight));
UE_LOG(LogTemp, Display, TEXT("Crouching Update"));
}
void AExoPlayerCharacter::CrouchingFinished()
{
}
void AExoPlayerCharacter::UpdateCameraHeight(float DeltaTime)
{
if (FMath::IsNearlyEqual(GetCurrentEyeHeight(), TargetEyeHeight, 0.01f))
{
return;
}
const float NewHeight = FMath::Lerp(GetCurrentEyeHeight(), TargetEyeHeight, DeltaTime*5);
const FVector CamRelXY = CameraComponent->GetRelativeLocation();
EyeHeight = GetFootOffset() + NewHeight;
CameraComponent->SetRelativeLocation(FVector(CamRelXY.X, CamRelXY.Y,EyeHeight));
}
void AExoPlayerCharacter::ApplyCameraOffsets(float DeltaTime)
{
bool HasChanged = false;
if (!FVector::PointsAreNear(EyeLocationOffset, TargetEyeLocationOffset, 0.01f))
{
// Smoothly offset view
EyeLocationOffset = FMath::Lerp(EyeLocationOffset, TargetEyeLocationOffset, 5*DeltaTime);
HasChanged = true;
}
if (!FMath::IsNearlyEqual(EyeRoll, TargetEyeRoll, 0.01f))
{
// Smoothly rotate view
EyeRoll = FMath::Lerp(EyeRoll, TargetEyeRoll, DeltaTime*5);
HasChanged = true;
}
if (!HasChanged)
{
// Do not calculate anything if nothing changed
return;
}
// Update actual camera position
const FVector FinalOffset = FVector(EyeLocationOffset.X, EyeLocationOffset.Y,
EyeLocationOffset.Z + TargetEyeHeight + GetFootOffset());
CameraComponent->SetRelativeLocation(FinalOffset);
// Update actual camera rotation (Roll)
FRotator NewRotator = GetController()->GetControlRotation();
NewRotator.Roll = EyeRoll;
GetController()->SetControlRotation(NewRotator);
}
void AExoPlayerCharacter::OnActorBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
if (OtherActor && OtherActor != this)
{
@ -96,6 +194,34 @@ void AExoPlayerCharacter::OnActorBeginOverlap(UPrimitiveComponent* OverlappedCom
}
}
void AExoPlayerCharacter::CrouchCustom()
{
SetTargetEyeHeight(CrouchedEyeHeight);
GetCharacterMovement()->MaxWalkSpeed = CrouchSpeed;
bIsCrouched = true;
CrouchTimeline.Play();
//float CurrentCamHeight = GetCurrentEyeHeight();
//GetCapsuleComponent()->SetCapsuleHalfHeight(GetCharacterMovement()->CrouchedHalfHeight);
// CameraComponent->SetRelativeLocation(
// FVector(0, 0, GetFootOffset()) +
// FVector(0, 0, CurrentCamHeight));
}
void AExoPlayerCharacter::TryUnCrouchCustom()
{
SetTargetEyeHeight(StandingEyeHeight);
GetCharacterMovement()->MaxWalkSpeed = WalkSpeed;
bIsCrouched = false;
CrouchTimeline.Reverse();
//float CurrentCamHeight = GetCurrentEyeHeight();
//GetCapsuleComponent()->SetCapsuleHalfHeight(StandingHalfHeight);
//CameraComponent->SetRelativeLocation(
// FVector(0, 0, GetFootOffset()) +
// FVector(0, 0, CurrentCamHeight));
}
void AExoPlayerCharacter::AddHealthPoints(float addValue)
{
CurrentHealth += addValue;
@ -106,3 +232,63 @@ void AExoPlayerCharacter::AddHealthPoints(float addValue)
if (PlayerHud)
PlayerHud->SetHp(CurrentHealth,MaxHealth);
}
float AExoPlayerCharacter::GetStandingEyeHeight(const bool bCapsuleRelative) const
{
return bCapsuleRelative ? StandingEyeHeight - GetCapsuleComponent()->GetScaledCapsuleHalfHeight()
: StandingEyeHeight;
}
float AExoPlayerCharacter::GetCrouchingEyeHeight(const bool bCapsuleRelative) const
{
return bCapsuleRelative ? CrouchedEyeHeight - GetCapsuleComponent()->GetScaledCapsuleHalfHeight()
: CrouchedEyeHeight;
}
bool AExoPlayerCharacter::IsCrouching() const
{
return bIsCrouched;
}
void AExoPlayerCharacter::SetEyePositionOffsetTarget(const FVector LocationOffset)
{
//LocationOffset.Z = FMath::Clamp(LocationOffset.Z, CoverEyeHeight, StandingEyeHeight);
UE_LOG(LogTemp, Log, TEXT("Eye offset set to: %s"), *LocationOffset.ToString());
TargetEyeLocationOffset = LocationOffset;
}
void AExoPlayerCharacter::SetEyeRoll(float RollValue)
{
TargetEyeRoll = RollValue;
}
FVector AExoPlayerCharacter::GetPlayerLocationAtFeet() const
{
FVector ReturnVector = GetActorLocation();
ReturnVector.Z -= GetCapsuleComponent()->GetScaledCapsuleHalfHeight();
return ReturnVector;
}
void AExoPlayerCharacter::SetTargetEyeHeight(float NewEyeHeight, const bool bCapsuleRelative)
{
if (bCapsuleRelative)
{
NewEyeHeight += GetCapsuleComponent()->GetScaledCapsuleHalfHeight();
}
UE_LOG(LogTemp, Log, TEXT("Target eye height set to: %f"), NewEyeHeight);
TargetEyeHeight = FMath::Clamp(NewEyeHeight,
CrouchedEyeHeight + LowEyeHeightOffset, StandingEyeHeight
);
}
float AExoPlayerCharacter::GetCurrentEyeHeight(const bool bCapsuleRelative) const
{
float ReturnValue = CameraComponent->GetRelativeLocation().Z;
if (!bCapsuleRelative)
{
ReturnValue += GetCapsuleComponent()->GetScaledCapsuleHalfHeight();
}
return ReturnValue;
}

View File

@ -5,9 +5,9 @@
#include "EnhancedInputComponent.h"
#include "EnhancedInputSubsystems.h"
#include "Characters/ExoPlayerCharacter.h"
#include "Components/CapsuleComponent.h"
#include "GameFramework/Character.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Kismet/GameplayStatics.h"
AExoPlayerController::AExoPlayerController()
{
@ -29,33 +29,32 @@ void AExoPlayerController::BeginPlay()
Subsystem->AddMappingContext(InputContext, 0);
}
//InteractionComponent = PlayerCharacter->FindComponentByClass<UInteractionComponent>();
//ShootingComponent = PlayerCharacter->FindComponentByClass<UShootingComponent>();
InteractionComponent = PlayerCharacter->InteractionComponent;
ShootingComponent = PlayerCharacter->ShootingComponent;
// Ustawianie w komponencie poruszania pr<70>dko<6B>ci zapisanej w characterze
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->WalkSpeed;
// Oblicz prawidłową maksymalną wysokość na którą można wychylić się z nad osłony
UE_LOG(LogTemp, Display, TEXT("MaxCoverAimHeight: %f"), MaxCoverAimHeight);
}
void AExoPlayerController::PlayerTick(float DeltaTime)
void AExoPlayerController::PlayerTick(const float DeltaTime)
{
Super::PlayerTick(DeltaTime);
// TESTING
if (bIsInCover)
{
AdjustCameraWhileInCover();
}
UpdateCoverStandHeight(DeltaTime);
bIsCoverAiming = (PlayerCharacter->bIsInCover && PlayerCharacter->bIsAimingMode);
if (bIsCoverAiming)
{
CoverAimHeightOffset = CalculateCoverAimOffset();
PlayerCharacter->SetEyePositionOffsetTarget(FVector(0.f, 0.f, CoverAimHeightOffset));
}
// On screen cover state DEBUG
if (bShowCoverSystemDebug)
{
GEngine->AddOnScreenDebugMessage(2, -1, FColor::Red, FString::Printf(TEXT("In cover: %s"), bIsInCover ? "true" : "false"));
GEngine->AddOnScreenDebugMessage(2, -1, FColor::Red,
FString::Printf(TEXT("In cover: %hs"),
PlayerCharacter->bIsInCover ? "true" : "false")
);
}
}
@ -119,6 +118,8 @@ void AExoPlayerController::Interact()
void AExoPlayerController::PlayerJump()
{
if (PlayerCharacter->IsCrouching()) return;
PlayerCharacter->Jump();
}
@ -152,21 +153,17 @@ void AExoPlayerController::ResetDodge()
void AExoPlayerController::PlayerStartCrouch()
{
if (bIsSprinting)
if (bIsSprinting && !bWasSliding)
{
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeedCrouched = PlayerCharacter->SlideSpeed;
GetWorldTimerManager().SetTimer(SlideCooldownTimer, this, &AExoPlayerController::ResetSlide, PlayerCharacter->SlideCooldown, false);
StartSlide();
return;
}
PlayerCharacter->Crouch();
PlayerCharacter->CameraComponent->SetRelativeLocation(FVector(
0.0f,
0.0f,
PlayerCharacter->CrouchedEyeHeight)
);
bWasSliding = false;
PlayerCharacter->CrouchCustom();
// Start checking for cover
bIsInCover = CheckForCover();
PlayerCharacter->bIsInCover = CheckForCover();
GetWorld()->GetTimerManager().SetTimer(
CoverCheckTimer,
this,
@ -178,22 +175,28 @@ void AExoPlayerController::PlayerStartCrouch()
void AExoPlayerController::PlayerStopCrouch()
{
PlayerCharacter->UnCrouch();
PlayerCharacter->CameraComponent->SetRelativeLocation(FVector(
0.0f,
0.0f,
PlayerCharacter->BaseEyeHeight)
);
PlayerCharacter->TryUnCrouchCustom();
// Stop checking for cover
GetWorld()->GetTimerManager().ClearTimer(CoverCheckTimer);
bIsInCover = false;
TargetCoverStandAlpha = 0.0f;
PlayerCharacter->bIsInCover = false;
}
void AExoPlayerController::StartSlide()
{
bIsSliding = true;
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->SlideSpeed;
PlayerCharacter->SetTargetEyeHeight(PlayerCharacter->LowEyeHeightOffset);
GetWorldTimerManager().SetTimer(SlideCooldownTimer, this, &AExoPlayerController::ResetSlide, PlayerCharacter->SlideCooldown, false);
}
void AExoPlayerController::ResetSlide()
{
PlayerCharacter->GetCharacterMovement()->MaxWalkSpeedCrouched = PlayerCharacter->CrouchSpeed;
bIsSliding = false;
bWasSliding = true;
PlayerStartCrouch();
//PlayerCharacter->GetCharacterMovement()->MaxWalkSpeed = PlayerCharacter->CrouchSpeed;
//PlayerCharacter->SetTargetEyeHeight(PlayerCharacter->CrouchedEyeHeight);
}
void AExoPlayerController::PlayerStartSprint()
@ -236,6 +239,10 @@ void AExoPlayerController::PlayerStartAim()
void AExoPlayerController::PlayerStopAim()
{
ShootingComponent->StopAiming();
if (PlayerCharacter->bIsInCover)
{
PlayerCharacter->SetEyePositionOffsetTarget(FVector(0, 0, 0));
}
}
void AExoPlayerController::PlayerMeleAttack()
@ -270,13 +277,13 @@ void AExoPlayerController::PlayerReload()
bool AExoPlayerController::CheckForCover()
{
// Cover is recalculated every time the player crouches or stops moving while crouched
// Cover targets are cleared completely when player stands up again or dies
// Do a simple 8-directional line trace
FVector TraceDirection = PlayerCharacter->GetActorForwardVector();
FVector TraceStart = PlayerCharacter->GetActorLocation();
TraceStart.Z -= PlayerCharacter->GetCapsuleComponent()->GetScaledCapsuleHalfHeight() - CoverObstacleMinHeight;
TraceStart.Z += bUseEyeHeight ?
PlayerCharacter->GetCrouchingEyeHeight(true)
:
PlayerCharacter->GetPlayerLocationAtFeet().Z + CoverObstacleMinHeight;
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(PlayerCharacter);
@ -306,10 +313,8 @@ bool AExoPlayerController::CheckForCover()
// Check if this particular hit isn't against a wall (>CoverMaxHeight)
FHitResult SphereHit;
FVector SpherePosition = Hit.ImpactPoint +
FVector(
0.0f, 0.0f,
CoverObstacleMaxHeight + CoverAimWindowRadius - CoverObstacleMinHeight);
FVector SpherePosition = Hit.ImpactPoint;
SpherePosition.Z = PlayerCharacter->GetPlayerLocationAtFeet().Z + CoverObstacleMaxHeight + CoverAimWindowRadius;
GetWorld()->SweepSingleByChannel(
SphereHit,
@ -342,20 +347,17 @@ bool AExoPlayerController::CheckForCover()
return ValidHits.Num() > 0;
}
void AExoPlayerController::AdjustCameraWhileInCover()
float AExoPlayerController::CalculateCoverAimOffset()
{
if (!bIsInCover)
// Nic nie rób jak nie znajdujesz się za osłoną
if (!PlayerCharacter->bIsInCover)
{
return;
return 0.f;
}
MaxCoverAimHeight = PlayerCharacter->StandingEyeHeight * CoverAimStandFactor;
// Oblicz maksymalną wysokość, na którą można wychylić się znad osłony
MaxCoverAimHeight = PlayerCharacter->GetStandingEyeHeight() * CoverAimStandFactor;
//FVector StartOffset = GetCharacter()->GetActorForwardVector() * 20.0f;
FVector ObstacleTraceStart = GetCharacter()->GetActorLocation();
ObstacleTraceStart.Z += GetCharacter()->CrouchedEyeHeight;
FVector ObstacleTraceEnd =
ObstacleTraceStart + PlayerCameraManager->GetCameraRotation().Vector() * CoverAimFreeDistance;
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(PlayerCharacter);
TEnumAsByte<ECollisionChannel> ObstacleTraceChannel = ECC_WorldStatic;
@ -363,159 +365,62 @@ void AExoPlayerController::AdjustCameraWhileInCover()
FHitResult Hit;
bool bFreeSpace = false;
// Trace until no hit is found (free space to aim)
for (int i = 0; i < MaxCoverAimHeight; i += 2*CoverAimWindowRadius)
FVector ObstacleTraceStart = PlayerCharacter->GetPlayerLocationAtFeet();
ObstacleTraceStart.Z += PlayerCharacter->CrouchedEyeHeight;
FVector ObstacleTraceEnd = ObstacleTraceStart + PlayerCameraManager->GetCameraRotation().Vector() * CoverAimFreeDistance;
float SafeCoverAimZOffset = 0.f;
while (SafeCoverAimZOffset < MaxCoverAimHeight)
{
ObstacleTraceStart.Z += i;
ObstacleTraceEnd.Z += i;
ObstacleTraceStart.Z += SafeCoverAimZOffset;
ObstacleTraceEnd.Z += SafeCoverAimZOffset;
GetWorld()->SweepSingleByChannel(
Hit,
ObstacleTraceStart,
ObstacleTraceEnd,
FQuat::Identity,
ObstacleTraceChannel,
FCollisionShape::MakeSphere(CoverAimWindowRadius),
QueryParams
);
Hit,
ObstacleTraceStart,
ObstacleTraceEnd,
FQuat::Identity,
ObstacleTraceChannel,
FCollisionShape::MakeSphere(CoverAimWindowRadius),
QueryParams
);
if (bShowCoverSystemDebug)
if (Hit.bBlockingHit == true)
{
DrawDebugSphere(GetWorld(), Hit.Location, CoverAimWindowRadius, 8,
Hit.bBlockingHit ? FColor::Blue : FColor::Red,
false, 0.0f, 0, 0);
// Increment check height every failed iteration
SafeCoverAimZOffset += 0.2f;
}
if (Hit.bBlockingHit == false)
else
{
UE_LOG(LogTemp, Display, TEXT("Free space"));
bFreeSpace = true;
// Break the loop if free space found
break;
}
}
if (bFreeSpace)
const float FinalHitHeight = Hit.TraceStart.Z - PlayerCharacter->GetPlayerLocationAtFeet().Z;
// If this is true that means that free space was found
if (FinalHitHeight <= MaxCoverAimHeight)
{
TargetCoverStandAlpha = FMath::GetMappedRangeValueClamped(
UE::Math::TVector2<float>(GetCharacter()->CrouchedEyeHeight, GetCharacter()->CrouchedEyeHeight + MaxCoverAimHeight),
UE::Math::TVector2(0.0f, 1.0f),
Hit.TraceStart.Z
);
PlayerCharacter->bIsCrouched = false;
//// DEBUG ////
if (bShowCoverSystemDebug)
{
DrawDebugLine(GetWorld(), Hit.TraceStart, Hit.TraceEnd, FColor::Red);
DrawDebugLine(GetWorld(), Hit.TraceStart, Hit.TraceEnd, FColor::Purple);
}
//////////////
return FinalHitHeight - PlayerCharacter->CrouchedEyeHeight;// +
//PlayerCharacter->CrouchedEyeHeight - PlayerCharacter->GetCurrentEyeHeight();
}
// IDEA FOR A MORE COMPLEX SYSTEM IN THE FUTURE:
//vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// To not introduce accidental flickering and optimize it a bit, all of this should run
// ONLY on cover update
// FVector CrouchedEyeWorldPosition = PlayerCharacter->GetActorLocation();
// CrouchedEyeWorldPosition.Z += PlayerCharacter->CrouchedEyeHeight;
// FVector CoverCeiling = CrouchedEyeWorldPosition + MaxCoverAimHeight;
// float PlayerCapsuleRadius = PlayerCharacter->GetCapsuleComponent()->GetScaledCapsuleHalfHeight();
// TEnumAsByte<ECollisionChannel> ObstacleTraceChannel = ECC_WorldStatic;
// FCollisionQueryParams QueryParams;
// QueryParams.AddIgnoredActor(PlayerCharacter);
//
// // Shoot ray up at maximum cover length to determine how high the player can "stand up"
// FHitResult WallTopHit;
// GetWorld()->SweepSingleByChannel(
// WallTopHit,
// CrouchedEyeWorldPosition,
// CoverCeiling,
// FQuat::Identity,
// ObstacleTraceChannel,
// FCollisionShape::MakeSphere(PlayerCapsuleRadius),
// QueryParams
// );
//
// FVector CeilingWorldLocation;
// if (WallTopHit.bBlockingHit == true)
// {
// CeilingWorldLocation = WallTopHit.Location;
// }
// else
// {
// CeilingWorldLocation = WallTopHit.TraceEnd;
// }
//
// // From hit location (or if no hit - from end position) shoot ray towards camera's forward
// // vector at minimum cover length
//
// constexpr float WallFinderDistance = 75.0f;
// FVector WallFinderDirection = PlayerCharacter->GetActorForwardVector();
// WallFinderDirection.Z = 0.0f; // Not needed if the player always stays upright
//
// GetWorld()->LineTraceSingleByChannel(
// WallTopHit,
// CeilingWorldLocation,
// CeilingWorldLocation + (WallFinderDirection * WallFinderDistance),
// ObstacleTraceChannel,
// QueryParams
// );
//
// // regardless of the hit result shoot multi-ray downwards from end location
// // with maximum cover length
//
// FVector WallTopTraceStart = WallTopHit.bBlockingHit ? WallTopHit.Location : WallTopHit.TraceEnd;
// TArray<FHitResult> ValidHitsCandidateArray;
//
// GetWorld()->LineTraceMultiByChannel(
// ValidHitsCandidateArray,
// WallTopTraceStart,
// WallTopTraceStart + (FVector(0.0f, 0.0f, 0.0f) * MaxCoverAimHeight),
// ObstacleTraceChannel,
// QueryParams
// );
// On every ray hit trace an in-place sphere to determine if the aiming spot is valid
// All valid aiming spots are collected and the lowest (smallest Z) is chosen
// Sphere trace from camera forward a certain distance to regulate camera position while
// aiming up and down // TODO: elaborate
}
void AExoPlayerController::UpdateCoverStandHeight(float DeltaTime)
{
// if (FMath::IsNearlyEqual(CoverStandAlpha, TargetCoverStandAlpha, 0.01f))
// {
// return;
// }
CoverStandAlpha = FMath::Lerp(CoverStandAlpha, TargetCoverStandAlpha, DeltaTime * 5.0f);
//CoverStandAlpha = TargetCoverStandAlpha;
// BANDAID SOLUTION
const float NewZ = FMath::Lerp(
PlayerCharacter->CrouchedEyeHeight,
PlayerCharacter->StandingEyeHeight,
CoverStandAlpha
);
PlayerCharacter->CameraComponent->SetRelativeLocation(
FVector(0.0f, 0.0f, NewZ)
);
if (bShowCoverSystemDebug && GEngine)
{
GEngine->AddOnScreenDebugMessage(1, -1, FColor::Red, FString::Printf(TEXT("Current cover stand alpha: %f"), CoverStandAlpha));
}
// Return 0 offset if no free space to aim was found
//return 0.f;
return MaxCoverAimHeight - PlayerCharacter->CrouchedEyeHeight;
}
void AExoPlayerController::OnCoverTimer()
{
bIsInCover = CheckForCover();
if (bIsInCover == false)
{
TargetCoverStandAlpha = 0.0f;
UpdateCoverStandHeight(GetWorld()->GetDeltaSeconds());
}
PlayerCharacter->bIsInCover = CheckForCover();
}
void AExoPlayerController::DebugCoverSystem(bool show)

View File

@ -99,6 +99,10 @@ public:
AGunBase* SecondaryGunBase = nullptr;
UStaticMeshComponent* SecondaryGunMesh = nullptr;
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnADSEventSignature);
FOnADSEventSignature OnStartedADS;
FOnADSEventSignature OnStoppedADS;
private:
void ResetFireCooldown();
void ReloadCompleted();

View File

@ -5,7 +5,7 @@
#include "CoreMinimal.h"
#include "Camera/CameraComponent.h"
#include "Characters/ExoCharacterBase.h"
#include "Components/CapsuleComponent.h"
#include "Components/TimelineComponent.h"
#include "ExoPlayerCharacter.generated.h"
class UInteractionComponent;
@ -20,6 +20,7 @@ class EXO_API AExoPlayerCharacter : public AExoCharacterBase
public:
AExoPlayerCharacter();
/// U PROPERTIES ///
UPROPERTY(EditAnywhere, Category = "Combat")
TObjectPtr<USkeletalMeshComponent> Weapon;
@ -32,8 +33,11 @@ public:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Camera")
TObjectPtr<UCameraComponent> CameraComponent;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Camera")
float StandingEyeHeight;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
TObjectPtr<USceneComponent> CapsuleBottom;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UI")
TSubclassOf<UUserWidget> PlayerHudClass;
UPROPERTY(EditAnywhere, Category = "Dodge Properties")
float DodgeForce = 5000.f;
@ -62,21 +66,109 @@ public:
UPROPERTY(EditAnywhere, Category = "Health")
float CurrentHealth = 50.0f;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UI")
TSubclassOf<UUserWidget> PlayerHudClass;
/// Połowa wysokości kapsuły gracza podczas stania
UPROPERTY(EditAnywhere, BlueprintReadOnly)
float StandingHalfHeight = 88.f;
/** Czy postać gracza jest obecnie schowana za osłoną */
UPROPERTY(BlueprintReadOnly, Category = "Cover System")
bool bIsInCover = false;
/** Offset kamery podczas leżenia (osłona, ślizg) <br>
* Bezpiecznie będzie założyć że to najniżej jak kamera
* może zejść podczas gameplaya
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Camera")
float LowEyeHeightOffset;
UPROPERTY(EditAnywhere)
TObjectPtr<UCurveFloat> CapsuleResizeCurve;
/// U FUNCTIONS ///
UFUNCTION()
void OnActorBeginOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult
);
/// Przełącza gracza w tryb kucania
UFUNCTION(BlueprintCallable, Category = "Movement")
void CrouchCustom();
/// Próbuje wyjść z trybu kucania
UFUNCTION(BlueprintCallable, Category = "Movement")
void TryUnCrouchCustom();
DECLARE_MULTICAST_DELEGATE(FOnPlayerCrouchEvent);
FOnPlayerCrouchEvent OnPlayerCrouchStart;
FOnPlayerCrouchEvent OnPlayerCrouchStop;
UFUNCTION()
void AddHealthPoints(float addValue);
UFUNCTION(BlueprintCallable, Category="Camera")
void SetEyePositionOffsetTarget(FVector LocationOffset);
UFUNCTION(BlueprintCallable, Category="Camera")
void SetEyeRoll(float RollValue);
UFUNCTION(BlueprintCallable)
FVector GetPlayerLocationAtFeet() const;
UFUNCTION(BlueprintCallable, Category="Camera")
void SetTargetEyeHeight(float NewEyeHeight, const bool bCapsuleRelative = false);
UFUNCTION(BlueprintCallable, Category="Camera")
float GetCurrentEyeHeight(const bool bCapsuleRelative = false) const;
UFUNCTION(BlueprintPure, Category="Camera")
float GetStandingEyeHeight(const bool bCapsuleRelative = false) const;
UFUNCTION(BlueprintPure, Category="Camera")
float GetCrouchingEyeHeight(const bool bCapsuleRelative = false) const;
UFUNCTION(BlueprintPure, Category="Movement")
bool IsCrouching() const;
protected:
virtual void BeginPlay() override;
virtual void Tick(float DeltaTime) override;
float MaxHealth = 100.0f;
UWBP_PlayerUI* PlayerHud;
/** Wysokość kamery podczas kucania jest dostarczana przez Character.h*/
/** Wysokość kamery podczas stania <br>
* Też najwyższa wysokość na którą kamera może się wznieść
* podczas gameplaya
*/
UPROPERTY(EditAnywhere, Category="Camera")
float StandingEyeHeight;
UFUNCTION(BlueprintCallable)
float GetFootOffset();
private:
FVector TargetEyeLocationOffset;
FVector EyeLocationOffset;
float TargetEyeRoll;
float EyeRoll;
float TargetEyeHeight;
float EyeHeight;
FTimeline CrouchTimeline;
UFUNCTION()
void CrouchingUpdate(float Alpha);
UFUNCTION()
void CrouchingFinished();
void UpdateCameraHeight(float DeltaTime);
void ApplyCameraOffsets(float DeltaTime);
};

View File

@ -25,6 +25,9 @@ public:
virtual void PlayerTick(float DeltaTime) override;
UPROPERTY(BlueprintReadOnly)
bool bIsCoverAiming = false;
protected:
virtual void SetupInputComponent() override;
@ -53,6 +56,9 @@ protected:
UFUNCTION(BlueprintCallable, Category = "Input")
void PlayerStopCrouch(); // LCtrl\C\X
UFUNCTION(BlueprintCallable, Category = "Movement")
void StartSlide();
UFUNCTION(BlueprintCallable, Category = "Input")
void ResetSlide();
@ -95,17 +101,9 @@ protected:
UFUNCTION(BlueprintCallable, Category = "Cover System")
bool CheckForCover();
UFUNCTION(BlueprintCallable, Category = "Cover System")
void AdjustCameraWhileInCover();
//DECLARE_MULTICAST_DELEGATE(FOnPlayerAimEvent);
UFUNCTION(BlueprintCallable, Category = "Cover System")
void UpdateCoverStandHeight(float DeltaTime);
void OnCoverTimer();
float MapAlphaToCoverStandHeight(float Alpha);
// DEBUG
// Cover System DEBUG
UFUNCTION(Exec, Category = "Cover System")
void DebugCoverSystem(bool show);
bool bShowCoverSystemDebug = false;
@ -147,6 +145,9 @@ protected:
UPROPERTY(EditAnywhere, Category = "Movement properties")
bool bIsSprinting = false;
UPROPERTY(EditAnywhere, Category = "Movement properties")
bool bIsSliding = false;
UPROPERTY(EditAnywhere, Category = "Input")
TObjectPtr<UInputAction> ShootAction;
@ -177,43 +178,40 @@ protected:
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Character")
TObjectPtr<AExoPlayerCharacter> PlayerCharacter;
// Czy postać gracza jest obecnie schowana za osłoną
UPROPERTY(EditAnywhere, Category = "Cover System")
bool bIsInCover = false;
/** Alpha wysokości kamery podczas wychulania zza osłony
* 0 - Wysokość kucania
* 1 - Maksymalna wysokość wychylenia określona przez CoverAimStandFactor
**/
UPROPERTY(EditAnywhere, Category = "Cover System")
float TargetCoverStandAlpha = 0.0f;
// Częstotliwość okresowego szukania osłon podczas kucania
/** Częstotliwość okresowego szukania osłon podczas kucania */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cover System")
float CoverCheckRate = 0.5f;
// Dystans na którym postać jest w stanie odnaleźć osłonę
/** Dystans na którym postać jest w stanie odnaleźć osłonę */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cover System")
float MaxDistanceFromCover = 50.0f;
// Minimalna wysokość przeszkody którą można określić osłoną
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cover System")
/** Używa wysokości oczu do określenia minimalnej wysokości przeszkody
* którą można określić osłoną
*/
UPROPERTY(EditAnywhere, Category = "Cover System")
bool bUseEyeHeight = true;
/** Minimalna wysokość przeszkody którą można określić osłoną */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cover System",
meta = (EditCondition = "!UseEyeHeight"))
float CoverObstacleMinHeight = 75.0f;
// Maksymalna wysokość przeszkody którą można określić osłoną
/** Maksymalna wysokość przeszkody którą można określić osłoną */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cover System")
float CoverObstacleMaxHeight = 125.0f;
// Promień wolnej przestrzeni przez którą można się wychylić
/** Promień wolnej przestrzeni przez którą można się wychylić */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cover System")
float CoverAimWindowRadius = 2.0f;
// Dystans od kamery po wychyleniu który musi być wolny by dało się wychylić
/** Dystans od kamery po wychyleniu który musi być wolny by dało się wychylić */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Cover System")
float CoverAimFreeDistance = 150.0f;
/** Określa na jaki procent "Stania" postać może się podnieść podczas celowania
* zza osłony. 0 -> Nie podniesie się wogóle (jakby wychylanie się było wyłączone)
* zza osłony.<br>
* 0 -> Nie podniesie się wogóle (jakby wychylanie się było wyłączone) <br>
* 1 -> Postać jest w stanie się podnieść do pełnej wysokości, tak jakby normalnie stała
**/
UPROPERTY(EditAnywhere,
@ -232,7 +230,13 @@ private:
UShootingComponent* ShootingComponent;
float CoverStandAlpha = 0.0f;
float CalculateCoverAimOffset();
void OnCoverTimer();
FTimerHandle CoverCheckTimer;
float MaxCoverAimHeight;
float CoverAimHeightOffset;
// temporary
bool bWasSliding = false;
};