Implemented a Recursive Function TestLOS() for Vision Link
Spots Enemies that spotted enemies can see until no more unique enemies are found within the collective vision
This commit is contained in:
		
							parent
							
								
									c764ce182a
								
							
						
					
					
						commit
						7bb582f636
					
				@ -1,3 +1,3 @@
 | 
			
		||||
version https://git-lfs.github.com/spec/v1
 | 
			
		||||
oid sha256:3dcf2376c901c20297196f292d3af9789583d7023bb529d5e347e29cf43967e1
 | 
			
		||||
size 14705
 | 
			
		||||
oid sha256:16b8ace32a02155ad001cb46a64f3b5bef4c4c4ae6f13f0a6e13ac5d683c9a3c
 | 
			
		||||
size 14694
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,3 @@
 | 
			
		||||
version https://git-lfs.github.com/spec/v1
 | 
			
		||||
oid sha256:2e54f66125275a7482edeefbb4f92ebba6bc1791877f697fd60c6051711946e7
 | 
			
		||||
size 98220
 | 
			
		||||
oid sha256:0d16edae7f13193d1183a5d98fe86bdc3c55fa37936345f8239280501fd89fd5
 | 
			
		||||
size 98008
 | 
			
		||||
 | 
			
		||||
@ -1,3 +1,3 @@
 | 
			
		||||
version https://git-lfs.github.com/spec/v1
 | 
			
		||||
oid sha256:e8b0e40ede14db8ce7ce78f51420e587af885afcbc93c4c0e8a24ec6798005ec
 | 
			
		||||
size 109679
 | 
			
		||||
oid sha256:9e3dc3ac3d7558e57253059c870b13d20e67e639f7a748c3c6a384d65ae7df7f
 | 
			
		||||
size 109712
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								EndlessVendetta/Content/StarterContent/Architecture/Floor_400x400.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								EndlessVendetta/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								EndlessVendetta/Content/StarterContent/HDRI/HDRI_Epic_Courtyard_Daylight.uasset
									 (Stored with Git LFS)
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							@ -3,6 +3,7 @@
 | 
			
		||||
 | 
			
		||||
#include "VisionLink.h"
 | 
			
		||||
 | 
			
		||||
#include "Kismet/KismetMathLibrary.h"
 | 
			
		||||
#include "Camera/CameraComponent.h"
 | 
			
		||||
#include "VisionLinkEnemyLOSTest.h"
 | 
			
		||||
#include "GameFramework/Character.h"
 | 
			
		||||
@ -42,17 +43,60 @@ void AVisionLink::SendOutPingPulse()
 | 
			
		||||
	UpdatePulsesRemaining(NumOfPingPulsesLeftInThisCycle);
 | 
			
		||||
	if (NumOfPingPulsesLeftInThisCycle < 0) return;
 | 
			
		||||
 | 
			
		||||
	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()
 | 
			
		||||
	// FActorSpawnParameters SpawnParams;
 | 
			
		||||
	// SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	//AActor* LOSTestActor = GetWorld()->SpawnActor<AActor>(EnemyLOSTestActor, SpawnLoc, GetActorRotation(), SpawnParams);
 | 
			
		||||
	// FVector SpawnLoc = PlayerCamComp->GetComponentLocation() + PlayerCamComp->GetForwardVector() * EnemyLOSTestActor->GetDefaultObject<AVisionLinkEnemyLOSTest>()->SpawnOffset;
 | 
			
		||||
	//
 | 
			
		||||
	//
 | 
			
		||||
	// AActor* LOSTestActor = GetWorld()->SpawnActor<AActor>(EnemyLOSTestActor, SpawnLoc, PlayerCamComp->GetComponentRotation(), 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);
 | 
			
		||||
	PlayPingPulseAnim(TimeInbetweenPingPulses);
 | 
			
		||||
 | 
			
		||||
	UCameraComponent* PlayerCamComp = Cast<UCameraComponent>(GetWorld()->GetFirstPlayerController()->GetCharacter()->GetComponentByClass(UCameraComponent::StaticClass()));
 | 
			
		||||
	TArray<AActor*> ActorsToIgnore;
 | 
			
		||||
	ActorsToIgnore.Add(GetWorld()->GetFirstPlayerController()->GetCharacter());
 | 
			
		||||
	TestLOS(PlayerCamComp->GetComponentTransform(), ActorsToIgnore);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AVisionLink::TestLOS(FTransform StartingPos, TArray<AActor*> &ActorsToIgnore)
 | 
			
		||||
{
 | 
			
		||||
	float H_DegreeIncrement = (float)H_FOV / (float)LT_Horizontal_Density;
 | 
			
		||||
	float V_DegreeIncrement = (float)V_FOV / (float)LT_Vertical_Density;
 | 
			
		||||
	float H_StartingRot = StartingPos.GetRotation().Rotator().Yaw - ((float)H_FOV / 2.0);
 | 
			
		||||
	float V_StartingRot = StartingPos.GetRotation().Rotator().Pitch - ((float)V_FOV / 2.0);
 | 
			
		||||
 | 
			
		||||
	for (int H_Increment = 1; H_Increment <= LT_Horizontal_Density; H_Increment++)
 | 
			
		||||
	{
 | 
			
		||||
		for (int V_Increment = 1; V_Increment <= LT_Vertical_Density; V_Increment++)
 | 
			
		||||
		{
 | 
			
		||||
			FHitResult outHit;
 | 
			
		||||
			FCollisionQueryParams QueryParams = FCollisionQueryParams::DefaultQueryParam;
 | 
			
		||||
			QueryParams.bTraceComplex = true;
 | 
			
		||||
			QueryParams.AddIgnoredActors(ActorsToIgnore);
 | 
			
		||||
			
 | 
			
		||||
			FRotator LT_Rot = FRotator(V_StartingRot + (V_Increment * V_DegreeIncrement), H_StartingRot + (H_Increment * H_DegreeIncrement), StartingPos.GetRotation().Rotator().Roll);
 | 
			
		||||
			FVector LT_EndPoint = StartingPos.GetLocation() + UKismetMathLibrary::GetForwardVector(LT_Rot) * LT_Distance;
 | 
			
		||||
			
 | 
			
		||||
			if (!GetWorld()->LineTraceSingleByChannel(outHit, StartingPos.GetLocation(), LT_EndPoint, ECC_Camera, QueryParams)) continue;
 | 
			
		||||
 | 
			
		||||
			// Only consider enemies which we haven't seen before
 | 
			
		||||
			AActor* HitActor = outHit.GetActor();
 | 
			
		||||
			if (!HitActor->ActorHasTag(FName("Enemy"))) continue; //|| EnemiesInLink.Contains(HitActor->GetUniqueID())) continue;
 | 
			
		||||
 | 
			
		||||
			DrawDebugLine(GetWorld(), outHit.TraceStart, outHit.ImpactPoint, FColor::Blue, false, 3, 0, 3);	
 | 
			
		||||
			ActorsToIgnore.Add(HitActor);
 | 
			
		||||
			UE_LOG(LogTemp, Warning, TEXT("I've Seen an Enemy called: %s"), *HitActor->GetName());
 | 
			
		||||
			TestLOS(HitActor->GetTransform(), ActorsToIgnore);
 | 
			
		||||
			
 | 
			
		||||
			
 | 
			
		||||
			
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -21,6 +21,8 @@ class ENDLESSVENDETTA_API AVisionLink : public AReconGadget
 | 
			
		||||
 | 
			
		||||
	FTimerHandle PulseHandle;
 | 
			
		||||
 | 
			
		||||
	void TestLOS(FTransform StartingPos, TArray<AActor*> &ActorsToIgnore);
 | 
			
		||||
	
 | 
			
		||||
	void SendOutPingPulse();
 | 
			
		||||
 | 
			
		||||
	virtual void BeginPlay() override;
 | 
			
		||||
@ -34,7 +36,24 @@ protected:
 | 
			
		||||
	int NumberOfPingPulses = 1;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(EditDefaultsOnly, Category = "Vision Link")
 | 
			
		||||
	TSubclassOf<AVisionLinkEnemyLOSTest> EnemyLOSTestActor;
 | 
			
		||||
	int LT_Horizontal_Density = 80;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(EditDefaultsOnly, Category = "Vision Link")
 | 
			
		||||
	int LT_Vertical_Density = 25;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(EditDefaultsOnly, Category = "Vision Link")
 | 
			
		||||
	float LT_Distance = 4000;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(EditDefaultsOnly, Category = "Vision Link")
 | 
			
		||||
	float H_FOV = 75;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(EditDefaultsOnly, Category = "Vision Link")
 | 
			
		||||
	float V_FOV = 25;
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	// UPROPERTY(EditDefaultsOnly, Category = "Vision Link")
 | 
			
		||||
	// TSubclassOf<AVisionLinkEnemyLOSTest> EnemyLOSTestActor;
 | 
			
		||||
 | 
			
		||||
	UPROPERTY(BlueprintReadOnly, Category = "Vision Link")
 | 
			
		||||
	float CooldownLength;
 | 
			
		||||
 | 
			
		||||
@ -48,7 +48,11 @@ void AVisionLinkEnemyLOSTest::TestLOS(TArray<uint32> EnemiesInLink, AActor* LOSA
 | 
			
		||||
	for (int i = 0; i < OverlappingEnemies.Num(); i++)
 | 
			
		||||
	{
 | 
			
		||||
		// Overlapping Enemies Array should only contain enemies which aren't already in the link
 | 
			
		||||
		if (!OverlappingEnemies[i]->ActorHasTag(FName("Enemy")) || EnemiesInLink.Contains(OverlappingEnemies[i]->GetUniqueID())) OverlappingEnemies.RemoveAt(i);
 | 
			
		||||
		if (!OverlappingEnemies[i]->ActorHasTag(FName("Enemy")) || EnemiesInLink.Contains(OverlappingEnemies[i]->GetUniqueID()))
 | 
			
		||||
		{
 | 
			
		||||
			UE_LOG(LogTemp, Warning, TEXT("enemy name: %s"), *OverlappingEnemies[i]->GetName());
 | 
			
		||||
			OverlappingEnemies.RemoveAt(i);
 | 
			
		||||
		} 
 | 
			
		||||
	}
 | 
			
		||||
	if (OverlappingEnemies.IsEmpty())
 | 
			
		||||
	{
 | 
			
		||||
@ -58,12 +62,12 @@ void AVisionLinkEnemyLOSTest::TestLOS(TArray<uint32> EnemiesInLink, AActor* LOSA
 | 
			
		||||
 | 
			
		||||
	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);
 | 
			
		||||
		UE_LOG(LogTemp, Warning, TEXT("enemy name: %s"), *Enemy->GetName());
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	//Destroy();
 | 
			
		||||
	Destroy();
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -18,7 +18,7 @@ protected:
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	UPROPERTY(EditDefaultsOnly, Category = "Vision Link")
 | 
			
		||||
	FVector SpawnOffset = FVector(0, 0, 0 );
 | 
			
		||||
	float SpawnOffset = 0;
 | 
			
		||||
	
 | 
			
		||||
	// Sets default values for this actor's properties
 | 
			
		||||
	AVisionLinkEnemyLOSTest();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user