I have been working on a personal project where i was trying to make particle system without the use of unreal’s component. I have completed most of it but i am not able to spawn it.
AParticle::AParticle()
{
// 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;
// setting mesh
MeshComp = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComp"));
MeshComp->SetCollisionEnabled(ECollisionEnabled::PhysicsOnly);
RootComponent = MeshComp;
// set the variables
mass = rand() % (MAX_MASS - MIN_MASS) + MIN_MASS;
//Velocity = FVector(rand_float(), rand_float(), rand_float()), MIN_INIT_VELOCITY + rand() * (MAX_INIT_VELOCITY - MIN_INIT_VELOCITY);
Velocity = FVector(0, 20, 0);
Acceleration = FVector(0, 9.8, 0);
lifespan = 100.0f;
ForceVe = FVector(0, 10, 0);
Location = FVector((1 - 2 * rand_float())*LENGTH, (1 - 2 * rand_float())*LENGTH, (1 - 2 * rand_float())*LENGTH);
}
// Called when the game starts or when spawned
void AParticle::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AParticle::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
Velocity.AddBounded(Acceleration);
Location.AddBounded(Velocity);
// cslculating acceleration
Acceleration = ForceVe / mass;
// calculating velocity
Velocity = Velocity + Acceleration * (DeltaTime / 1000.0);
if (Velocity.Size() >= MAX_VELOCITY)
Velocity = FVector(Velocity.IsUnit(10), MAX_VELOCITY, 0);
//changing position
Location = Location + Velocity * (DeltaTime / 1000.0);
DeltaTime++;
const float LENGTH = 100.0f;
if (Location.X <= -LENGTH)
Location.X = LENGTH;
else if (Location.X >= LENGTH)
Location.X = -LENGTH;
if (Location.Y <= -LENGTH)
Location.Y = LENGTH;
else if (Location.Y >= LENGTH)
Location.Y = -LENGTH;
if (Location.Z <= -LENGTH)
Location.Z = LENGTH;
else if (Location.Z >= LENGTH)
Location.Z = -LENGTH;
}
this is what i have for the particle class.
for the emitter:
if (n1 > MAX_PARTICLES)
n1 = MAX_PARTICLES;
for (int i = 0; i < n1; i++)
{
//_particles += n1[i];
Particles_Alive.Push(_particles);
}
}
// Called when the game starts or when spawned
void AParticle_Emitter::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AParticle_Emitter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (_particles == nullptr)
{
return;
}
Particles_Alive.Add(_particles);
for (int32 i = 0; i < Particles_Alive.Num(); ++i)
{
Particles_Alive[i] = _particles;
Particles_Alive.Push(_particles);
if (_particles)
{
_particles->ForceVe;
_particles->Tick(DeltaTime);
}
//Particles_Alive[i]->ForceVe;
//Particles_Alive[i]->Tick(DeltaTime);
}
}
i have this for emitter any suggestion on what i need to have to make it spawn and act like particles.