diff --git a/Source/LegumeMix/Private/LMSpawnPosition.cpp b/Source/LegumeMix/Private/LMSpawnPosition.cpp index c8a727d..74c1c0a 100644 --- a/Source/LegumeMix/Private/LMSpawnPosition.cpp +++ b/Source/LegumeMix/Private/LMSpawnPosition.cpp @@ -5,6 +5,7 @@ #include "Kismet/GameplayStatics.h" #include "Engine/World.h" #include "DrawDebugHelpers.h" +#include "Camera/CameraComponent.h" // Sets default values ALMSpawnPosition::ALMSpawnPosition() @@ -23,7 +24,11 @@ bool ALMSpawnPosition::CanSpawn() void ALMSpawnPosition::BeginPlay() { Super::BeginPlay(); - + AActor* Player = UGameplayStatics::GetPlayerPawn(GetWorld(), 0); + if (Player) + { + PlayerCamera = Player->FindComponentByClass(); + } } // Called every frame @@ -39,7 +44,7 @@ bool ALMSpawnPosition::IsPlayerVisible() const if (!Player) return false; FVector Start = GetActorLocation(); - FVector End = Player->GetActorLocation(); + FVector End = PlayerCamera->GetComponentLocation(); FHitResult HitResult; FCollisionQueryParams Params; diff --git a/Source/LegumeMix/Public/LMSpawnPosition.h b/Source/LegumeMix/Public/LMSpawnPosition.h index 8542849..4d5bd49 100644 --- a/Source/LegumeMix/Public/LMSpawnPosition.h +++ b/Source/LegumeMix/Public/LMSpawnPosition.h @@ -6,6 +6,8 @@ #include "GameFramework/Actor.h" #include "LMSpawnPosition.generated.h" +class UCameraComponent; + UCLASS() class LEGUMEMIX_API ALMSpawnPosition : public AActor { @@ -26,6 +28,9 @@ protected: virtual void BeginPlay() override; virtual void EndCooldown(); + + UPROPERTY() + UCameraComponent* PlayerCamera = nullptr; public: // Called every frame