Fixed LOS Test Missing Actor Reference

This commit is contained in:
Rafal Swierczek 2023-10-03 12:39:20 +01:00
parent 826243de51
commit c764ce182a
8 changed files with 27 additions and 18 deletions

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3dcf2376c901c20297196f292d3af9789583d7023bb529d5e347e29cf43967e1
size 14705

Binary file not shown.

Binary file not shown.

View File

@ -3,6 +3,10 @@
#include "VisionLink.h"
#include "Camera/CameraComponent.h"
#include "VisionLinkEnemyLOSTest.h"
#include "GameFramework/Character.h"
void AVisionLink::BeginPlay()
{
Super::BeginPlay();
@ -38,13 +42,15 @@ void AVisionLink::SendOutPingPulse()
UpdatePulsesRemaining(NumOfPingPulsesLeftInThisCycle);
if (NumOfPingPulsesLeftInThisCycle < 0) return;
//FActorSpawnParameters SpawnParams;
//SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
//FVector SpawnLoc = (GetActorLocation() - EquippedOffset) + EnemyLOSTestActor.GetDefaultObject()->SpawnOffset;
FActorSpawnParameters SpawnParams;
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
UCameraComponent* PlayerCamComp = Cast<UCameraComponent>(GetWorld()->GetFirstPlayerController()->GetCharacter()->GetComponentByClass(UCameraComponent::StaticClass()));
//FVector SpawnLoc = PlayerCamComp->GetSocketLocation(NAME_None) + PlayerCamComp->GetForwardVector() * EnemyLOSTestActor->GetDefaultObject()
AActor* LOSTestActor = GetWorld()->SpawnActor<AActor>(EnemyLOSTestActor, SpawnLoc, GetActorRotation(), SpawnParams);
TArray<FString> EmptyFStringArray;
Cast<AVisionLinkEnemyLOSTest>(LOSTestActor)->TestLOS(EmptyFStringArray, GetOwner());
//AActor* LOSTestActor = GetWorld()->SpawnActor<AActor>(EnemyLOSTestActor, SpawnLoc, GetActorRotation(), SpawnParams);
//TArray<uint32> EmptyIDArray;
//Cast<AVisionLinkEnemyLOSTest>(LOSTestActor)->TestLOS(EmptyIDArray, this);
UE_LOG(LogTemp, Warning, TEXT("Ping Pulse!"));
GetWorld()->GetTimerManager().SetTimer(PulseHandle, this, &AVisionLink::SendOutPingPulse, TimeInbetweenPingPulses, false);

View File

@ -28,7 +28,7 @@ void AVisionLinkEnemyLOSTest::Tick(float DeltaTime)
}
void AVisionLinkEnemyLOSTest::TestLOS(TArray<FString> EnemiesInLink, AActor* LOSActor)
void AVisionLinkEnemyLOSTest::TestLOS(TArray<uint32> EnemiesInLink, AActor* LOSActor)
{
// Get all overlapping Actors
UBoxComponent* CollisionBox = Cast<UBoxComponent>(GetComponentByClass(UBoxComponent::StaticClass()));
@ -47,9 +47,8 @@ void AVisionLinkEnemyLOSTest::TestLOS(TArray<FString> EnemiesInLink, AActor* LOS
for (int i = 0; i < OverlappingEnemies.Num(); i++)
{
UE_LOG(LogTemp, Warning, TEXT("Overlapping Enemy Name: %s"), *OverlappingEnemies[i]->GetName());
// Overlapping Enemies Array should only contain enemies which aren't already in the link
if (!OverlappingEnemies[i]->ActorHasTag(FName("Enemy")) || EnemiesInLink.Contains(OverlappingEnemies[i]->GetName())) OverlappingEnemies.RemoveAt(i);
if (!OverlappingEnemies[i]->ActorHasTag(FName("Enemy")) || EnemiesInLink.Contains(OverlappingEnemies[i]->GetUniqueID())) OverlappingEnemies.RemoveAt(i);
}
if (OverlappingEnemies.IsEmpty())
{
@ -59,11 +58,12 @@ void AVisionLinkEnemyLOSTest::TestLOS(TArray<FString> EnemiesInLink, AActor* LOS
for (AActor* Enemy : OverlappingEnemies)
{
if (!IsValid(LOSActor)) UE_LOG(LogTemp, Fatal, TEXT("im an idiot"));
FRotator LookAtRotation = UKismetMathLibrary::FindLookAtRotation(LOSActor->GetActorLocation(), Enemy->GetActorLocation());
UE_LOG(LogTemp, Warning, TEXT("Look at Rotation: %f"), LookAtRotation.Yaw);
}
Destroy();
//Destroy();
}

View File

@ -26,5 +26,5 @@ public:
// Called every frame
virtual void Tick(float DeltaTime) override;
void TestLOS(TArray<FString> EnemiesInLink, AActor* LOS_Actor);
void TestLOS(TArray<uint32> EnemiesInLink, AActor* LOS_Actor);
};