Particles don't disappear

Posted By: Yking

Particles don't disappear - 10/15/14 19:30

Hello everyone,
I am trying very hard not to be too annoying :),
I wanted to learn how to use particles and surfed the
internet a bit, found a "Particle Effect Builder"-program and
played around a bit until I got something to work that I seem to understand mostly.

My only problem that I can't solve is:
The emitter keeps generating particles and the particles do not disappear. The "lifespan" of a particle does not have any actual effect for me. In the "Particle Effect Builder"-program everything seems to work fine, but as code it does not.

The code here is all generated with this program,
the emitter is placed in my mainfunction and is working, the only problem is.. well, the particles wont disappear.

Quote:

/////////////////////////////////untitled.c/////////////////////////////////
//
//Generated by Parted by Martin Coumont (redphoenix)
//
//LiteC Script file from 15.10.2014 ; 15:31:15:
//
//////////////////////////////////////////////////////////////////////////////

#include <acknex.h>
#include <default.c>

/////////////////////////////////header/////////////////////////////////

#ifndef PARTED_VECTOR_DEF
#define PARTED_VECTOR_DEF
VECTOR* parted_temp_vec = { x=0;y=0;z=0; }
VECTOR* parted_temp2_vec = { x=0;y=0;z=0; }
ANGLE* parted_temp_ang = { pan=0;tilt=0;roll=0; }
#endif

#ifndef PARTED_RANGEFUNC_DEF
#define PARTED_RANGEFUNC_DEF
function range(x,y,z) {
z+=y;
if(x >= y && x <= z) return(1);
return(0);
}
#endif

/////////////////////////////////particle code/////////////////////////////////

function Base_Effect_base_event(PARTICLE* p) {
p.vel_x = sinv(p.skill_d*3.6+180)*p.skill_x;
p.vel_y = cosv(p.skill_d*3.6)*p.skill_y;
p.vel_z = p.skill_z;
if(p.creator)vec_rotate(p.vel_x,p.creator.pan);
p.skill_d = (p.skill_d + time_step*(var)0.100)%100;
}

function Base_Effect_base(PARTICLE* p) {
p.size = 200.000;
p.alpha = 100.000;
p.red = 255;
p.green = 255;
p.blue = 0;
p.skill_c = 0.5;
p.vel_x = random(10.000)+(-5.000);
p.vel_y = random(10.000)+(-5.000);
p.vel_z = (50.000);
if(p.creator)vec_rotate(p.vel_x,p.creator.pan);
p.lifespan = 1;
p.gravity = 0.000;
p.flags = BRIGHT | MOVE;
p.skill_x = p.vel_x;
p.skill_y = p.vel_y;
p.skill_z = p.vel_z;
p.event = Base_Effect_base_event;
}

/////////////////////////////////timetableemitter actions/////////////////////////////////

action Base_Effect_emitter() {
var my_time;my_time = 0;
var timetable_num;timetable_num = 0;
var eff_frac; eff_frac = 0;
wait(1);
while(my) {
my_time += time_step/16;
if(my_time >= 0.000)my_time = 0;
timetable_num = 1;
parted_temp_vec.x = 0.000;
parted_temp_vec.y = 0.000;
parted_temp_vec.z = 0.000;
vec_rotate(parted_temp_vec,my.pan);
vec_add(parted_temp_vec,my.x);
eff_frac += 0.075*timetable_num*time_step*6.25;
if(eff_frac >= 1){
effect(Base_Effect_base,integer(eff_frac),parted_temp_vec,nullvector);
eff_frac -= integer(eff_frac);
}
wait(1);
}
}
/////////////////////////////////creation/////////////////////////////////

function effect_create(VECTOR* position) {
if(!position)position = nullvector;
wait(3);
you = ent_create(NULL,position,Base_Effect_emitter);
if(you) {
set(you,PASSABLE);
set(you,INVISIBLE);
}
}


(Right now, I think the lifespan of one particle should be 1 Frame/Tick, so it should disappear super fast if it would work)

Thanks for any help laugh
Posted By: Fred_Flintstones

Re: Particles don't disappear - 10/16/14 08:06

Awhile back I was messing around with particles and had the same issue. I found that if you put some code in the p.event function (Base_Effect_base_event) to put lifespan to 0. it fixed the problem.

EXMAPLE:
function Base_Effect_base_event(PARTICLE* p) {
p.vel_x = sinv(p.skill_d*3.6+180)*p.skill_x;
p.vel_y = cosv(p.skill_d*3.6)*p.skill_y;
p.vel_z = p.skill_z;
if(p.creator)vec_rotate(p.vel_x,p.creator.pan);
p.skill_d +=1*time_step;
if(p.skill_d>=1)p.lifespan=0;
}

I simply used skill_d because the one in your function seemed pointless.
Hope this helps.
Posted By: Yking

Re: Particles don't disappear - 10/16/14 09:18

Hello and thanks for your help so far,
I took your code and put it in like this:

Quote:

p.skill_a += 1 * time_step;
if (p.skill_a >= 1) {p.lifespan = 0;}

if (p.lifespan == 0) {printf("Lifespan is Zero");}


I used skill_a so I dont get confused while experimenting and also put in a printf to see if what the lifespan actually is.
I get a messagebox every frame, so I am very sure that the lifespan actually is 0. But still my particles do not disappear. When I press F11 I can see the counter going up endlessly. Could there be any mistake in the code?
Posted By: Yking

Re: Particles don't disappear - 10/16/14 19:44

I will post a stand-alone-code for my problem in case someone wants to try to solve it. I really have no idea what I am doing wrong confused

Quote:

/////////////////////////////////untitled.c/////////////////////////////////
//
//Generated by Parted by Martin Coumont (redphoenix)
//
//LiteC Script file from 15.10.2014 ; 15:31:15:
//
//////////////////////////////////////////////////////////////////////////////

#include <acknex.h>
#include <default.c>

/////////////////////////////////header/////////////////////////////////

#ifndef PARTED_VECTOR_DEF
#define PARTED_VECTOR_DEF
VECTOR* parted_temp_vec = { x=0;y=0;z=0; }
VECTOR* parted_temp2_vec = { x=0;y=0;z=0; }
ANGLE* parted_temp_ang = { pan=0;tilt=0;roll=0; }
#endif

#ifndef PARTED_RANGEFUNC_DEF
#define PARTED_RANGEFUNC_DEF
function range(x,y,z) {
z+=y;
if(x >= y && x <= z) return(1);
return(0);
}
#endif

/////////////////////////////////particle code/////////////////////////////////

function Base_Effect_base_event(PARTICLE* p) {
p.vel_x = sinv(p.skill_d*3.6+180)*p.skill_x;
p.vel_y = cosv(p.skill_d*3.6)*p.skill_y;
p.vel_z = p.skill_z;
if(p.creator)vec_rotate(p.vel_x,p.creator.pan);

p.skill_a += 1 * time_step;
if (p.skill_a >= 30) {p.lifespan = 0;}

//if (p.lifespan == 0) {printf("Lifespan is Zero");}

}

function Base_Effect_base(PARTICLE* p) {
p.size = 200.000;
p.alpha = 100.000;
p.red = 255;
p.green = 255;
p.blue = 0;
p.skill_c = 0.5;
p.vel_x = random(10.000)+(-5.000);
p.vel_y = random(10.000)+(-5.000);
p.vel_z = (50.000);
if(p.creator)vec_rotate(p.vel_x,p.creator.pan);
p.gravity = 0.000;
p.flags = BRIGHT | MOVE;
p.skill_x = p.vel_x;
p.skill_y = p.vel_y;
p.skill_z = p.vel_z;
p.event = Base_Effect_base_event;
}

/////////////////////////////////timetableemitter actions/////////////////////////////////

action Base_Effect_emitter() {
var my_time;my_time = 0;
var timetable_num;timetable_num = 0;
var eff_frac; eff_frac = 0;
wait(1);
while(my) {
my_time += time_step/16;
if(my_time >= 0.000)my_time = 0;
timetable_num = 1;
parted_temp_vec.x = 0.000; //Partikelstart-Positonen
parted_temp_vec.y = 0.000; //Partikelstart-Positonen
parted_temp_vec.z = 0.000; //Partikelstart-Positonen
vec_rotate(parted_temp_vec,my.pan);
vec_add(parted_temp_vec,my.x);
eff_frac += 0.075*timetable_num*time_step*6.25;
if(eff_frac >= 1){
effect(Base_Effect_base,integer(eff_frac),parted_temp_vec,nullvector);
eff_frac -= integer(eff_frac);
}
wait(1);
}
}
/////////////////////////////////creation/////////////////////////////////

function item_particle_effect_create(VECTOR* position) {
if(!position)position = nullvector;
wait(3);
you = ent_create(NULL,position,Base_Effect_emitter);
if(you) {
set(you,PASSABLE);
set(you,INVISIBLE);
}
}


function main()
{
vec_set(sky_color,vector(10,10,10));
level_load (NULL);
item_particle_effect_create(NULL);
vec_set(camera.x,vector(-380,-400,500));
camera.pan = 45;
camera.tilt = -30;
}


Press F11 and you see the Particle-Counter is endlessly going up
Posted By: Fred_Flintstones

Re: Particles don't disappear - 10/16/14 19:59

I copy and pasted your code.
Added a main function:

void main(){
level_load(NULL);
effect_create(vector(1000,0,0));
while(1){
DEBUG_VAR(num_particles,100);
wait(1);
}
}

So I could see if it was working and there doesn't seem to be any issues with the code...

You don't happen to call the function "effect_create(some_vector)" multiple times (like in a while loop) do you? because that would spam create entities that all produce particles.

EDIT: I see you posted again....I may change this post.
Posted By: Yking

Re: Particles don't disappear - 10/16/14 20:00

Well, it seems like I accidentally solved the problem xD.
It looks like I only need to change

Quote:

p.flags = BRIGHT | MOVE;


to

Quote:

p.flags |= BRIGHT | MOVE;


Then I dont need this function (but still thanks for it laugh )
Quote:
//p.skill_a += 1 * time_step;
//if (p.skill_a >= 30) {p.lifespan = 0;}

and the Particles cap at around 37-38 in my case.

I have no idea how that worked shocked
© 2024 lite-C Forums