From cb0230d24f70eb07151d8b7b7da876d6f857382d Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 30 Jul 2025 17:59:14 +0100 Subject: [PATCH] Gate Setting Actor Location Behind Bounds Check --- Source/vampires/PlayerCharacter.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Source/vampires/PlayerCharacter.cpp b/Source/vampires/PlayerCharacter.cpp index 198d129..de309bd 100644 --- a/Source/vampires/PlayerCharacter.cpp +++ b/Source/vampires/PlayerCharacter.cpp @@ -61,7 +61,7 @@ void APlayerCharacter::Tick(float DeltaTime) { Super::Tick(DeltaTime); - auto PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0); + APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0); FVector TopLeft, TopLeftDir; FVector BottomRight, BottomRightDir; @@ -72,11 +72,14 @@ void APlayerCharacter::Tick(float DeltaTime) PlayerController->DeprojectScreenPositionToWorld(0, 0, TopLeft, TopLeftDir); PlayerController->DeprojectScreenPositionToWorld(ViewportSize.X, ViewportSize.Y, BottomRight, BottomRightDir); - auto location = GetActorLocation(); - location.X = FMath::Clamp(location.X, BottomRight.X, TopLeft.X); - location.Y = FMath::Clamp(location.Y, TopLeft.Y, BottomRight.Y); + FVector Location = GetActorLocation(); + if (Location.X < BottomRight.X || Location.X > TopLeft.X || Location.Y > BottomRight.Y || Location.Y < TopLeft.Y) + { + Location.X = FMath::Clamp(Location.X, BottomRight.X, TopLeft.X); + Location.Y = FMath::Clamp(Location.Y, TopLeft.Y, BottomRight.Y); - SetActorLocation(location); + SetActorLocation(Location); + } } UEXPComponent* APlayerCharacter::GetEXPComponent() @@ -105,8 +108,6 @@ void APlayerCharacter::OnDeath(FDamageInfo damageInfo) { UGameplayStatics::PlaySoundAtLocation(GetWorld(), OnDeathSound, GetActorLocation()); } - - // TODO: End the game } void APlayerCharacter::CameraShakeTimelineCallback(float val)