Spawn enemy outside of camera view
This commit is contained in:
parent
2e59bb6e0e
commit
24d5eb9eaf
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "VampireGameMode.h"
|
#include "VampireGameMode.h"
|
||||||
|
|
||||||
|
#include "Components/CapsuleComponent.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
void AVampireGameMode::BeginPlay()
|
void AVampireGameMode::BeginPlay()
|
||||||
|
@ -59,6 +60,11 @@ void AVampireGameMode::SpawnEnemy()
|
||||||
FActorSpawnParameters SpawnParameters;
|
FActorSpawnParameters SpawnParameters;
|
||||||
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
SpawnParameters.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
|
||||||
|
|
||||||
AEnemyCharacter* actor = GetWorld()->SpawnActor<AEnemyCharacter>(EnemyTemplate, Transform, SpawnParameters);
|
AEnemyCharacter* Actor = GetWorld()->SpawnActor<AEnemyCharacter>(EnemyTemplate, Transform, SpawnParameters);
|
||||||
actor->SpawnDefaultController();
|
float CapsuleRadius = Actor->GetCapsuleComponent()->GetScaledCapsuleRadius();
|
||||||
|
FVector Direction = SpawnLocation - PlayerCharacter->GetActorLocation();
|
||||||
|
Direction.Normalize();
|
||||||
|
Direction *= CapsuleRadius;
|
||||||
|
Actor->SetActorLocation(SpawnLocation + Direction);
|
||||||
|
Actor->SpawnDefaultController();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue