Changed checking method for SpawnPosition

This commit is contained in:
sSebster 2025-04-08 19:21:00 +02:00
parent f147527812
commit 35a1cd757b
2 changed files with 12 additions and 2 deletions

View File

@ -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<UCameraComponent>();
}
}
// 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;

View File

@ -6,6 +6,8 @@
#include "GameFramework/Actor.h"
#include "LMSpawnPosition.generated.h"
class UCameraComponent;
UCLASS()
class LEGUMEMIX_API ALMSpawnPosition : public AActor
{
@ -27,6 +29,9 @@ protected:
virtual void EndCooldown();
UPROPERTY()
UCameraComponent* PlayerCamera = nullptr;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;