Spawn enemy outside of camera view

This commit is contained in:
baz 2024-06-27 17:46:27 +01:00
parent 2e59bb6e0e
commit 24d5eb9eaf
1 changed files with 8 additions and 2 deletions

View File

@ -3,6 +3,7 @@
#include "VampireGameMode.h"
#include "Components/CapsuleComponent.h"
#include "Kismet/GameplayStatics.h"
void AVampireGameMode::BeginPlay()
@ -59,6 +60,11 @@ void AVampireGameMode::SpawnEnemy()
FActorSpawnParameters SpawnParameters;
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
AEnemyCharacter* actor = GetWorld()->SpawnActor<AEnemyCharacter>(EnemyTemplate, Transform, SpawnParameters);
actor->SpawnDefaultController();
AEnemyCharacter* Actor = GetWorld()->SpawnActor<AEnemyCharacter>(EnemyTemplate, Transform, SpawnParameters);
float CapsuleRadius = Actor->GetCapsuleComponent()->GetScaledCapsuleRadius();
FVector Direction = SpawnLocation - PlayerCharacter->GetActorLocation();
Direction.Normalize();
Direction *= CapsuleRadius;
Actor->SetActorLocation(SpawnLocation + Direction);
Actor->SpawnDefaultController();
}