this spawns near the player, but physics are borked

This commit is contained in:
Brandon Thomas
2021-03-03 04:38:43 -05:00
parent d9335f3398
commit 5d13060cf4
@@ -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.