void ASpawnVolume::SpawnPickup()
{
	// If we have set something to spawn:
	if (whatToSpawn != NULL)
	{
		// Check for a valid world:
		UWorld* const World = GetWorld();
		if (World)
		{
			// Set the spawn parameters
			FActorSpawnParameters spawnParams;
			spawnParams.Owner = this;
			spawnParams.Instigator = Instigator;

			// Get a random location to spawn
			FVector spawnLocation = GetRandomPointInVolume();

			// Get a random rotation
			FRotator spawnRotation;
			spawnRotation.Yaw = FMath::FRand() * 360.0f;
			spawnRotation.Pitch = FMath::FRand() * 360.0f;
			spawnRotation.Roll = FMath::FRand() * 360.0f;
			
			// Spawn the pickup
			APickUp* const spawnedPickup = World->SpawnActor<APickUp>(whatToSpawn, spawnLocation, spawnRotation, spawnParams);

			spawnDelay = FMath::FRandRange(spawnDelayRangeLow, spawnDelayRangeHigh);
			GetWorldTimerManager().SetTimer(spawnTimer, this, &ASpawnVolume::SpawnPickup, spawnDelay, false);
		}
	}
}
Пример #2
0
void ASpawnVolume::SpawnPickup()
{
	// If we have set something to spawn:
	if (WhatToSpawn[0] != NULL)
	{
		// Check for a valid World: 
		UWorld* const World = GetWorld();
		if (World)
		{
			// Set the spawn parameters
			FActorSpawnParameters SpawnParams;
			SpawnParams.Owner = this;
			SpawnParams.Instigator = Instigator;

			// Get a random location to spawn at
			FVector SpawnLocation = GetRandomPointInVolume();

			// Get a random rotation for the spawned item
			FRotator SpawnRotation;
			SpawnRotation.Yaw = 90.f;
			SpawnRotation.Pitch = 0.f;
			SpawnRotation.Roll = 0.f;

			// spawn the pickup
			SpawnedPickup = World->SpawnActor<AActor>(WhatToSpawn[FMath::Rand()%ArraySize], SpawnLocation, SpawnRotation, SpawnParams);
		}
	}
}
Пример #3
0
void ASpawnVolume::SpawnPickup()
{
	// if we have set something to spawn:
	if (WhatToSpawn != NULL)
	{
		// Check for a valid World:
		UWorld* const World = GetWorld();
		if (World)
		{
			// Set the spawn parameters
			FActorSpawnParameters SpawnParams;
			SpawnParams.Owner = this;
			SpawnParams.Instigator = Instigator;

			// Get a random location to spawn at
			FVector SpawnLocation = GetRandomPointInVolume();

			// Get a random rotation for the spawn item
			FRotator SpawnRotation;
			SpawnRotation.Yaw = FMath::FRand() * 360.0f;
			SpawnRotation.Pitch = FMath::FRand() * 360.0f;
			SpawnRotation.Roll = FMath::FRand() * 360.0f;
			
			// spawn the pickup
			APickup* const SpawnPickup = World->SpawnActor <APickup>(WhatToSpawn, SpawnLocation, SpawnRotation, SpawnParams);
			GetWorldTimerManager().SetTimer(SpawnTimer, this, &ASpawnVolume::SpawnPickup, SpawnDelay, false);
		}

		
	}
}
Пример #4
0
void ASpawnVolume::SpawnPickup()
{
	// If we have set something to spawn
	if (WhatToSpawn != NULL)
	{
		// check for valid world
		UWorld* const World = GetWorld();
		if (World)
		{
			// Set the spawn paramters
			FActorSpawnParameters SpawnParams;
			SpawnParams.Owner = this;
			SpawnParams.Instigator = Instigator;

			// Get a random location to spawn
			FVector SpawnLocation = GetRandomPointInVolume();

			// Get a random rotation of the spawned item
			FRotator SpawnRotation;
			SpawnRotation.Yaw = FMath::FRand() * 360.f;
			SpawnRotation.Pitch = FMath::FRand() * 360.f;
			SpawnRotation.Roll = FMath::FRand() * 360.f;

			// spawn the pickup
			ASpawnableItem* const SpawnedPickup = UInventoryItemFactory::SpawnSpawnableItemFromClass(WhatToSpawn, 1, World, SpawnLocation, SpawnRotation, true);
		}
	}
}
Пример #5
0
void ASpawnVolume::SpawnPickup()
{
	// If we have something to spawn
	if (nullptr != WhatToSpawn)
	{
		// Check for a valid World
		UWorld* const World = GetWorld();
		if (nullptr != World)
		{
			// Set the spawn parameters
			FActorSpawnParameters SpawnParams;
			SpawnParams.Owner = this;
			SpawnParams.Instigator = Instigator;

			// Get a random location and a random rotation
			const FVector SpawnLocation = GetRandomPointInVolume();
			const FRotator SpawnRotation = UKismetMathLibrary::RandomRotator(true);

			// Spawn the pickup
			APickup* const SpawndPickup = World->SpawnActor<APickup>(WhatToSpawn, SpawnLocation, SpawnRotation, SpawnParams);

			// Start a timer to spawn a new Pickup after a delay
			const float SpawnDelay = FMath::RandRange(MinimumSpawnDelay, MaximumSpawnDelay);
			GetWorldTimerManager().SetTimer(SpawnTimer, this, &ASpawnVolume::SpawnPickup, SpawnDelay, false);
			UE_LOG(QuickStart, Log, TEXT("ASpawnVolume(%s): SetTimer(%f)"), *WhatToSpawn->GetName(), SpawnDelay);
		}
	}
}
Пример #6
0
void ASpawnVolume::SpawnPickup()
{
	// If we have set something to spawn.
	if (WhatToSpawn != NULL)
	{
		// Check for a valid world
		UWorld* const World = GetWorld();
		if (World)
		{
			// Set the spawn parameters.
			FActorSpawnParameters SpawnParams;
			SpawnParams.Owner = this;
			SpawnParams.Instigator = Instigator;
			
			// Get a random location to spawn at
			FVector SpawnLocation = GetRandomPointInVolume();

			// Get a random rotation for the spawned item
			FRotator SpawnRotation;
			SpawnRotation.Yaw = FMath::FRand() * 360.0f;
			SpawnRotation.Pitch = FMath::FRand() * 360.0f;
			SpawnRotation.Roll = FMath::FRand() * 360.0f;

			// spawn the pickup
			APickup* const SpawnedPickup = World->SpawnActor<APickup>(WhatToSpawn, SpawnLocation, SpawnRotation, SpawnParams);
		}
	}
}
Пример #7
0
void ASpawningVolume::SpawnShip(AShip* ShipToSpawn){
	FVector PossibleSpawnPoint;
	UWorld* World = GetWorld();
	FHitResult HitResult;
	FCollisionQueryParams Params;
	Params.bFindInitialOverlaps = true; 
	PossibleSpawnPoint = GetRandomPointInVolume();
	ShipToSpawn->SetActorLocation(PossibleSpawnPoint);
	
}
Пример #8
0
void ASpawnVolume::SpawnPickup() {

	if (WhatToSpawn != NULL)
	{
		//Checks if world is valid
		UWorld* const World = GetWorld();
		if (World) {
			TArray<AActor*> CollectedActors;
			WhereToSpawn->GetOverlappingActors(CollectedActors);
			int actorcount = CollectedActors.Num();

			if (actorcount < MaxPickups) {

				FActorSpawnParameters SpawnParams;
				SpawnParams.Owner = this;
				SpawnParams.Instigator = Instigator;

				//Get a Random point to spawn
				FVector SpawnLocation = GetRandomPointInVolume();

				//Gets a random rotation
				FRotator SpawnRotation;
				SpawnRotation.Yaw = FMath::FRand()*360.0f;
				SpawnRotation.Pitch = FMath::FRand()*360.0f;
				SpawnRotation.Roll = FMath::FRand()*360.0f;

				//If less than 5 actors spawn pickup 
				//TODO: Array also pickups player actor create an array that only stores actors//
				if (CollectedActors.Num() < MaxPickups) {
					APickup* const SpawnedPickup = World->SpawnActor<APickup>(WhatToSpawn, SpawnLocation, SpawnRotation, SpawnParams);
					UE_LOG(LogClass, Log, TEXT("There are %d actor(s)"), actorcount);
				}
				else {
					UE_LOG(LogClass, Log, TEXT("Too many pickups on field, there are %d actors the max is %d"), actorcount, MaxPickups);
				}

				//Sets Spawn Delay after one is spawned
				SpawnDelay = FMath::FRandRange(SpawnDelayRangeLow, SpawnDelayRangeHigh);
				GetWorldTimerManager().SetTimer(SpawnTimer, this, &ASpawnVolume::SpawnPickup, SpawnDelay, false);

			}
		}
	}
}
Пример #9
0
FVector ASpawningVolume::returnRandomLocation()
{
	FVector PossibleSpawnPoint;
	UWorld* World = GetWorld();
	FHitResult HitResult;
	FCollisionQueryParams Params;
	Params.bFindInitialOverlaps = true;
	if (World){
		do{
			PossibleSpawnPoint = GetRandomPointInVolume();
			if (!World->LineTraceSingle(HitResult, PossibleSpawnPoint, FVector(PossibleSpawnPoint.X, PossibleSpawnPoint.Y, -100), Params, FCollisionObjectQueryParams())){
				break;
			}
			AActor* Actor = HitResult.Actor.Get();
			FString name = Actor->GetActorLabel();
		} while (!HitResult.Actor.Get()->GetActorLabel().StartsWith("Floor"));
	}
	return PossibleSpawnPoint;
}
Пример #10
0
void ASpawnVolume::SpawnPickup()
{
	if (m_WhereToSpawn != NULL)
	{
		UWorld * const world = GetWorld();
		if (world)
		{
			FActorSpawnParameters spawnParams;
			spawnParams.Owner = this;
			spawnParams.Instigator = Instigator;

			FVector spawnLocation = GetRandomPointInVolume();

			FRotator spawnRotation;
			spawnRotation.Yaw = FMath::FRand() * 360.f;
			spawnRotation.Pitch = FMath::FRand() * 360.f;
			spawnRotation.Roll = FMath::FRand() * 360.f;

			AActor * const spawnedPickup = world->SpawnActor<AActor>(m_WhatToSpawn, spawnLocation, spawnRotation, spawnParams);
		}
	}
}