unrealgame4/Source/ThirdPerson/Private/BallActor.cpp

61 lines
2.1 KiB
C++
Raw Permalink Normal View History

// All content (c) Shaun Reed 2021, all rights reserved
#include "BallActor.h"
#include "Components/SphereComponent.h"
#include "Particles/ParticleSystemComponent.h"
// Sets default values
ABallActor::ABallActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
// Attach a sphere with the name 'Sphere'
SphereComp = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere"));
// Attach a static mesh component with the name 'MeshComp'; etc..
StaticMeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
ParticleComp = CreateDefaultSubobject<UParticleSystemComponent>(TEXT("ParticleComp"));
// Attach the sphere to the root position of this Actor and configure settings
SphereComp->SetupAttachment(RootComponent);
SphereComp->SetSimulatePhysics(true);
SphereComp->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
// Attach the static mesh to the sphere
StaticMeshComp->AttachToComponent(SphereComp, FAttachmentTransformRules::KeepRelativeTransform);
// Attach the particle system to the static mesh
ParticleComp->AttachToComponent(StaticMeshComp, FAttachmentTransformRules::KeepRelativeTransform);
// Set sphere radius to be smaller size in line with the static mesh (?)
SphereComp->SetSphereRadius(16.0f * this->sizeScale);
StaticMeshComp->SetRelativeLocation(FVector(0.0f, 0.0f, -12.0f));
StaticMeshComp->SetRelativeScale3D(FVector(0.25f, 0.25f, 0.25f));
static ConstructorHelpers::FObjectFinder<UStaticMesh>SphereMeshAsset(TEXT("StaticMesh'/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere'"));
StaticMeshComp->SetStaticMesh(SphereMeshAsset.Object);
static ConstructorHelpers::FObjectFinder<UParticleSystem>ParticleCompAsset(TEXT("ParticleSystem'/Game/StarterContent/Particles/P_Fire.P_Fire'"));
ParticleComp->SetTemplate(ParticleCompAsset.Object);
}
// Called when the game starts or when spawned
void ABallActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ABallActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}