Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,310 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Particles don't disappear #446447
10/15/14 19:30
10/15/14 19:30
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
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

Re: Particles don't disappear [Re: Yking] #446455
10/16/14 08:06
10/16/14 08:06
Joined: Aug 2014
Posts: 7
F
Fred_Flintstones Offline
Newbie
Fred_Flintstones  Offline
Newbie
F

Joined: Aug 2014
Posts: 7
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.

Re: Particles don't disappear [Re: Fred_Flintstones] #446457
10/16/14 09:18
10/16/14 09:18
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
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?

Re: Particles don't disappear [Re: Yking] #446476
10/16/14 19:44
10/16/14 19:44
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
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

Last edited by Yking; 10/16/14 19:45.
Re: Particles don't disappear [Re: Yking] #446477
10/16/14 19:59
10/16/14 19:59
Joined: Aug 2014
Posts: 7
F
Fred_Flintstones Offline
Newbie
Fred_Flintstones  Offline
Newbie
F

Joined: Aug 2014
Posts: 7
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.

Last edited by Fred_Flintstones; 10/16/14 20:01.
Re: Particles don't disappear [Re: Yking] #446478
10/16/14 20:00
10/16/14 20:00
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
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


Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1