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 "Kismet/GameplayStatics.h"
void UPartySubsystem::AddToParty(UUnitInfo* UnitInfo)
{
for (FPartyMember &Unit : Members)
@ -32,7 +34,13 @@ int32 UPartySubsystem::SpawnParty(const float InVerticalSpacing, const float InH
this->HorizontalOffset = InHorizontalOffset;
this->NumRows = InNumRows;
this->HorizontalSpacing = InHorizontalSpacing;
CurrentColumn = 0;
SpawnQueue.Empty();
TArray<AActor*> SpawnPoints;
UGameplayStatics::GetAllActorsWithTag(GetWorld(), "PlayerSpawn", SpawnPoints);
SpawnPoint = SpawnPoints[0];
for (FPartyMember &Unit : GetMembers())
{
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();
GetWorld()->GetTimerManager().SetTimer(
@ -68,8 +76,22 @@ void UPartySubsystem::SpawnUnits()
FActorSpawnParameters SpawnActorParameters = {};
SpawnActorParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
FVector Location = FVector( VerticalSpacing * i - VerticalSpacing, -HorizontalOffset * CurrentColumn, 1000);
GetWorld()->SpawnActor(SpawnQueue[i + LastSpawnIndex], &Location, nullptr, SpawnActorParameters);
FVector Location = SpawnPoint->GetActorLocation() + FVector(i * -VerticalSpacing, -HorizontalOffset * CurrentColumn, 300);
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;

@ -3,6 +3,8 @@
#include "WaveSubsystem.h"
#include "Kismet/GameplayStatics.h"
void UWaveSubsystem::Init(const TArray<UWave*> InWaves, const int32 CurrWave = 0)
{
CurrentWave = CurrWave;
@ -16,6 +18,11 @@ int32 UWaveSubsystem::SpawnWave(const float InVerticalSpacing, const float InHor
VerticalSpacing = InVerticalSpacing;
SpawnQueue = Waves[CurrentWave]->GetUnits();
const auto NumUnits = SpawnQueue.Num();
CurrentColumn = 0;
TArray<AActor*> SpawnPoints;
UGameplayStatics::GetAllActorsWithTag(GetWorld(), "EnemySpawn", SpawnPoints);
SpawnPoint = SpawnPoints[0];
SpawnUnits();
GetWorld()->GetTimerManager().SetTimer(
@ -36,15 +43,33 @@ void UWaveSubsystem::SpawnUnits()
if(i + LastSpawnIndex >= SpawnQueue.Num())
{
GetWorld()->GetTimerManager().ClearTimer(SpawnTimerHandle);
LastSpawnIndex += i;
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)
{
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;

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

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

Loading…
Cancel
Save