diff --git a/Source/EventCenterPlugin/Private/SpawningActor.cpp b/Source/EventCenterPlugin/Private/SpawningActor.cpp index e310ea7..dc60178 100644 --- a/Source/EventCenterPlugin/Private/SpawningActor.cpp +++ b/Source/EventCenterPlugin/Private/SpawningActor.cpp @@ -43,15 +43,30 @@ ASpawnableActor* ASpawningActor::Spawn() // TODO(bt): This will memory leak. ASpawnableActor* spawnedActor = (ASpawnableActor*)GetWorld()->SpawnActor(ASpawnableActor::StaticClass()); + // Get player location + FVector playerLocation = GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation(); + + // Teleport actor randomly // TODO(bt): Put this in front of the camera, or on the (camera -> player) arc! - float x = FMath::RandRange(-1000.0f, 1000.0f); - float y = FMath::RandRange(-1000.0f, 1000.0f); - float z = FMath::RandRange(-1000.0f, 1000.0f); + float x = FMath::RandRange(-100.0f, 100.0f); + float y = FMath::RandRange(-100.0f, 100.0f); + float z = FMath::RandRange(-100.0f, 100.0f); + + FVector location( + playerLocation.X + x, + playerLocation.Y + y, + playerLocation.Z + z + ); - FVector location(x, y, z); FRotator rotation; - spawnedActor->SetActorLocationAndRotation(location, rotation, false, 0, ETeleportType::ResetPhysics); + spawnedActor->SetActorLocationAndRotation( + location, + rotation, + false, + 0, + ETeleportType::ResetPhysics + ); // We don't want to keep the actor around indefinitely since they may pile up unused. // Optionally, we could maintain a queue and cull the oldest actors.