Actor
范围内随机生成 Learn Unreal Engine (with C++)
SpaceshipBattle · fanxingin/UE4项目 - 码云 - 开源中国 (gitee.com)
Actor
范围内随机生成
-
新建
box
组件SpawnArea = CreateDefaultSubobject<UBoxComponent>(TEXT("SpawnArea"));RootComponent = SpawnArea;
-
获取随机生成位置
FVector AEnemySpawner::GetGenerateLocation() {float Distance = 0;FVector Location;while (Distance< MinimumDistanceToPlayer){//在盒子中产生的随机的点Location = UKismetMathLibrary::RandomPointInBoundingBox(SpawnArea->Bounds.Origin, SpawnArea->Bounds.BoxExtent);Distance = (Location - SpaceShip->GetActorLocation()).Size();}return Location; }
-
在指定位置生成
Actor
FActorSpawnParameters SpawnParameters;// 生成敌人GetWorld()->SpawnActor<AEnemy>(Enemy, GetGenerateLocation(), FRotator::ZeroRotator, SpawnParameters);