Added spawn raycasting, correct facing and spacing

feature/spawn-fix
Jers 11 months ago
parent 84643b06f7
commit b4b1f869a6

Binary file not shown.

BIN
Content/Blueprints/BP_PlayerPawn.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Blueprints/BP_SpawnPoint.uasset (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

BIN
Content/Levels/BattleMap.umap (Stored with Git LFS)

Binary file not shown.

BIN
Content/Levels/MainMenu.umap (Stored with Git LFS)

Binary file not shown.

Binary file not shown.

@ -3,6 +3,8 @@
#include "PartySubsystem.h" #include "PartySubsystem.h"
#include "Kismet/GameplayStatics.h"
void UPartySubsystem::AddToParty(UUnitInfo* UnitInfo) void UPartySubsystem::AddToParty(UUnitInfo* UnitInfo)
{ {
for (FPartyMember &Unit : Members) for (FPartyMember &Unit : Members)
@ -32,7 +34,13 @@ int32 UPartySubsystem::SpawnParty(const float InVerticalSpacing, const float InH
this->HorizontalOffset = InHorizontalOffset; this->HorizontalOffset = InHorizontalOffset;
this->NumRows = InNumRows; this->NumRows = InNumRows;
this->HorizontalSpacing = InHorizontalSpacing; this->HorizontalSpacing = InHorizontalSpacing;
CurrentColumn = 0;
SpawnQueue.Empty();
TArray<AActor*> SpawnPoints;
UGameplayStatics::GetAllActorsWithTag(GetWorld(), "PlayerSpawn", SpawnPoints);
SpawnPoint = SpawnPoints[0];
for (FPartyMember &Unit : GetMembers()) for (FPartyMember &Unit : GetMembers())
{ {
for(auto i = 0; i < GetMemberAllocated(Unit); i++) for(auto i = 0; i < GetMemberAllocated(Unit); i++)
@ -41,7 +49,7 @@ int32 UPartySubsystem::SpawnParty(const float InVerticalSpacing, const float InH
} }
} }
const auto NumUnits= SpawnQueue.Num(); const int32 NumUnits = SpawnQueue.Num();
SpawnUnits(); SpawnUnits();
GetWorld()->GetTimerManager().SetTimer( GetWorld()->GetTimerManager().SetTimer(
@ -68,8 +76,22 @@ void UPartySubsystem::SpawnUnits()
FActorSpawnParameters SpawnActorParameters = {}; FActorSpawnParameters SpawnActorParameters = {};
SpawnActorParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn; SpawnActorParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
FVector Location = FVector( VerticalSpacing * i - VerticalSpacing, -HorizontalOffset * CurrentColumn, 1000); FVector Location = SpawnPoint->GetActorLocation() + FVector(i * -VerticalSpacing, -HorizontalOffset * CurrentColumn, 300);
GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex], &Location, nullptr, SpawnActorParameters); FRotator Rotation = FRotator(0, 90.0f, 0);
AActor* NewActor = GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex], &Location, &Rotation, SpawnActorParameters);
FHitResult Hit;
FVector TraceStart = NewActor->GetActorLocation();
FVector TraceEnd = -NewActor->GetActorUpVector() * 10000.0f;
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(NewActor);
NewActor->GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_WorldStatic, QueryParams);
if(Hit.bBlockingHit)
{
NewActor->SetActorLocation(Hit.Location, true, nullptr, ETeleportType::ResetPhysics);
}
} }
LastSpawnIndex += NumRows; LastSpawnIndex += NumRows;

@ -3,6 +3,8 @@
#include "WaveSubsystem.h" #include "WaveSubsystem.h"
#include "Kismet/GameplayStatics.h"
void UWaveSubsystem::Init(const TArray<UWave*> InWaves, const int32 CurrWave = 0) void UWaveSubsystem::Init(const TArray<UWave*> InWaves, const int32 CurrWave = 0)
{ {
CurrentWave = CurrWave; CurrentWave = CurrWave;
@ -16,6 +18,11 @@ int32 UWaveSubsystem::SpawnWave(const float InVerticalSpacing, const float InHor
VerticalSpacing = InVerticalSpacing; VerticalSpacing = InVerticalSpacing;
SpawnQueue = Waves[CurrentWave]->GetUnits(); SpawnQueue = Waves[CurrentWave]->GetUnits();
const auto NumUnits = SpawnQueue.Num(); const auto NumUnits = SpawnQueue.Num();
CurrentColumn = 0;
TArray<AActor*> SpawnPoints;
UGameplayStatics::GetAllActorsWithTag(GetWorld(), "EnemySpawn", SpawnPoints);
SpawnPoint = SpawnPoints[0];
SpawnUnits(); SpawnUnits();
GetWorld()->GetTimerManager().SetTimer( GetWorld()->GetTimerManager().SetTimer(
@ -36,15 +43,33 @@ void UWaveSubsystem::SpawnUnits()
if(i + LastSpawnIndex >= SpawnQueue.Num()) if(i + LastSpawnIndex >= SpawnQueue.Num())
{ {
GetWorld()->GetTimerManager().ClearTimer(SpawnTimerHandle); GetWorld()->GetTimerManager().ClearTimer(SpawnTimerHandle);
LastSpawnIndex += i;
return; return;
} }
FActorSpawnParameters SpawnActorParameters = {};
SpawnActorParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
FVector Location = SpawnPoint->GetActorLocation() + FVector(i * -VerticalSpacing, -HorizontalOffset * CurrentColumn, 300);
FRotator Rotation = FRotator(0,-90.0f, 0);
AActor* NewEnemy = GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex]->GetCharacterClass(), &Location, &Rotation, SpawnActorParameters);
FVector Location = FVector(VerticalSpacing * i - VerticalSpacing, HorizontalOffset, 0);
AActor* NewEnemy = GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex]->GetCharacterClass(), &Location);
if(NewEnemy != nullptr) if(NewEnemy != nullptr)
{ {
NewEnemy->Tags.Add(TEXT("enemy")); NewEnemy->Tags.Add(TEXT("enemy"));
} }
FHitResult Hit;
FVector TraceStart = NewEnemy->GetActorLocation();
FVector TraceEnd = -NewEnemy->GetActorUpVector() * 10000.0f;
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(NewEnemy);
NewEnemy->GetWorld()->LineTraceSingleByChannel(Hit, TraceStart, TraceEnd, ECC_WorldStatic, QueryParams);
if(Hit.bBlockingHit)
{
NewEnemy->SetActorLocation(Hit.Location, true, nullptr, ETeleportType::ResetPhysics);
}
} }
LastSpawnIndex += NumRows; LastSpawnIndex += NumRows;

@ -78,6 +78,9 @@ protected:
UPROPERTY(BlueprintReadWrite, EditAnywhere) UPROPERTY(BlueprintReadWrite, EditAnywhere)
int32 Credits; int32 Credits;
UPROPERTY()
AActor* SpawnPoint;
FTimerHandle SpawnTimerHandle; FTimerHandle SpawnTimerHandle;
int32 LastSpawnIndex; int32 LastSpawnIndex;

@ -20,7 +20,7 @@ public:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
int32 SpawnWave(float InVerticalSpacing, float InHorizontalOffset, int InNumRows); int32 SpawnWave(float InVerticalSpacing, float InHorizontalOffset, int InNumRows);
protected: protected:
void SpawnUnits(); void SpawnUnits();
@ -35,10 +35,14 @@ protected:
UPROPERTY(BlueprintReadWrite) UPROPERTY(BlueprintReadWrite)
UPrimaryDataAsset* SelectedStage; UPrimaryDataAsset* SelectedStage;
UPROPERTY()
AActor* SpawnPoint;
FTimerHandle SpawnTimerHandle; FTimerHandle SpawnTimerHandle;
int32 NumRows; int32 NumRows;
int32 LastSpawnIndex; int32 LastSpawnIndex;
float VerticalSpacing; float VerticalSpacing;
float HorizontalOffset; float HorizontalOffset;
int32 CurrentColumn;
}; };

Loading…
Cancel
Save