Skip to content

Commit f62e457

Browse files
committed
Added 'SpawnVolume' C++ class
1 parent e8d7b34 commit f62e457

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

Content/Maps/CollectionLevel.umap

-620 Bytes
Binary file not shown.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Fill out your copyright notice in the Description page of Project Settings.
2+
3+
#include "BatteryCollector.h"
4+
#include "SpawnVolume.h"
5+
#include "Kismet/KismetMathLibrary.h"
6+
7+
8+
// Sets default values
9+
ASpawnVolume::ASpawnVolume()
10+
{
11+
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
12+
PrimaryActorTick.bCanEverTick = false;
13+
14+
// Create the Box Component to represent the spawn volume
15+
WhereToSpawn = CreateDefaultSubobject<UBoxComponent>(TEXT("WhereToSpawn"));
16+
RootComponent = WhereToSpawn;
17+
}
18+
19+
// Called when the game starts or when spawned
20+
void ASpawnVolume::BeginPlay()
21+
{
22+
Super::BeginPlay();
23+
24+
}
25+
26+
// Called every frame
27+
void ASpawnVolume::Tick( float DeltaTime )
28+
{
29+
Super::Tick( DeltaTime );
30+
31+
}
32+
33+
FVector ASpawnVolume::GetRandomPointInVolume()
34+
{
35+
FVector SpawnOrigin = WhereToSpawn->Bounds.Origin;
36+
FVector SpawnExtent = WhereToSpawn->Bounds.BoxExtent;
37+
38+
return UKismetMathLibrary::RandomPointInBoundingBox(SpawnOrigin, SpawnExtent);
39+
40+
}
41+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Fill out your copyright notice in the Description page of Project Settings.
2+
3+
#pragma once
4+
5+
#include "GameFramework/Actor.h"
6+
#include "SpawnVolume.generated.h"
7+
8+
UCLASS()
9+
class BATTERYCOLLECTOR_API ASpawnVolume : public AActor
10+
{
11+
GENERATED_BODY()
12+
13+
public:
14+
// Sets default values for this actor's properties
15+
ASpawnVolume();
16+
17+
// Called when the game starts or when spawned
18+
virtual void BeginPlay() override;
19+
20+
// Called every frame
21+
virtual void Tick( float DeltaSeconds ) override;
22+
23+
/**Returns the WhereToSpawn subobject */
24+
FORCEINLINE class UBoxComponent* GetWhereToSpawn() const { return WhereToSpawn; }
25+
26+
/** Find a random point within the BoxComponent */
27+
UFUNCTION(BlueprintPure, Category = "Spawning")
28+
FVector GetRandomPointInVolume();
29+
30+
private:
31+
/** Box Component to specify where pickups should be spawned */
32+
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Spawning", meta = (AllowPrivateAccess = "true"))
33+
class UBoxComponent* WhereToSpawn;
34+
35+
};

0 commit comments

Comments
 (0)